home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / MacSNMP / SNMP Agents Dev Kit / Library Manager Interfaces / LibraryManagerClasses.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  82.1 KB  |  3,082 lines  |  [TEXT/MPS ]

  1. /*    File:        LibraryManagerClasses.h
  2.  
  3.     Contains:    Declarations for ASLM classes
  4.  
  5.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGERCLASSES__
  11. #define __LIBRARYMANAGERCLASSES__
  12.  
  13. #ifndef __LIBRARYMANAGER__
  14. #include <LibraryManager.h>
  15. #endif
  16.  
  17. /*******************************************************************************
  18. ** Forward class declarations
  19. ********************************************************************************/
  20.  
  21. #ifdef __cplusplus
  22. class TOperation;
  23. class TStandardPool;
  24. class TTraceLog;
  25. class TTaskScheduler;
  26. class TArbitrator;
  27. class TTime;
  28. class TPoolNotifier;
  29. class TRequestToken;
  30. class TToken;
  31. #else
  32. typedef void TOperation;
  33. typedef void TTraceLog;
  34. typedef void TArbitrator;
  35. typedef void TTaskScheduler;
  36. #endif
  37.  
  38. /*******************************************************************************
  39. ** Some typedefs and enums
  40. ********************************************************************************/
  41.  
  42. //
  43. //    PointerType is mainly used for the TCollection::DeleteAll method so the collection
  44. //    knows what type of objects are in the collection so it can do the proper cast
  45. //    and call the destructor (if it really is an object).
  46. //
  47. typedef int                PointerType;
  48.  
  49. #define kVoidPointer        ((PointerType)0)    /* a non-object pointer */
  50. #define kTDynamicPointer    ((PointerType)1)    /* SingleObject with vtable first */
  51. #define kTSCDynamicPointer    ((PointerType)1)    /* subclass of TSCDynamic */
  52. #define kTSCPointer            ((PointerType)2)    /* A Think C++ Object */
  53. #define kTStdDynamicPointer    ((PointerType)3)    /* non-SingleObject with vtable first */
  54.  
  55. typedef unsigned long    EventCode;
  56.  
  57. #define kTokenNotification        ((EventCode)0x40000001)
  58. #define kLowPoolMemoryEvent        ((EventCode)0x40000002)
  59. #define kHighPoolMemoryEvent    ((EventCode)0x40000003)
  60. #define kDownsizePoolEvent        ((EventCode)0x40000004)
  61. #define kDeathEvent                ((EventCode)0x40000005)
  62.  
  63. typedef void            (* MPWC ProcessProcPtr)(TOperation*);
  64.  
  65. typedef unsigned long    (* MPWC HashProcPtr)(const void*);
  66. typedef Boolean            (* MPWC IsEqualProcPtr)(const void* ref, const void* toComp);
  67. typedef int                (* MPWC CompareProcPtr)(const void* ref, const void* toComp);
  68.  
  69. // Below is a typedef for a pointer to a notify method for an object. Ignore the
  70. // fact the the typedef claims that it needs to be a TDynamic method. It can be
  71. // any kind of class. The only caveat is that if the NotifyMethod is a virtual
  72. // function, the vtable for the object must be the first field of the object.
  73. // You can force the vtable to be first by creating a base class that has atleast
  74. // one virtual function and no data members, like TDynamic does.
  75. #ifdef __cplusplus
  76. typedef void        (TDynamic::* MPWC NotifyMethodPtr)(EventCode, OSErrParm, void* notifyData);
  77. typedef NotifyMethodPtr    NotifyMethod;
  78. #endif
  79. typedef void        (* MPWC NotifyProcPtr)(void* refPtr, EventCode, OSErrParm, void* notifyData);
  80.  
  81. //
  82. // These are for compatibility with ASLM 1.1
  83. //
  84. typedef ProcessProcPtr    ProcessProc;
  85. typedef HashProcPtr        HashProc;
  86. typedef IsEqualProcPtr    IsEqualProc;
  87. typedef CompareProcPtr    CompareProc;
  88. typedef NotifyProcPtr    NotifyProc;
  89.  
  90. /*******************************************************************************
  91. ** Some "C" Global routines
  92. ********************************************************************************/
  93.  
  94. #ifdef __cplusplus
  95. extern "C"
  96. {
  97. #endif
  98.     TTraceLog*        GetGlobalTraceLog();
  99.     void            SetGlobalTraceLog(TTraceLog*);
  100.     void            Trace(const char *formatStr, ...);
  101.  
  102.     TArbitrator*    GetGlobalArbitrator();
  103.     TTaskScheduler*    GetGlobalTaskScheduler();
  104.     void            DestroyPointer(void*, PointerType);
  105. #ifdef __cplusplus
  106. };
  107. #endif
  108.  
  109. #ifdef __cplusplus
  110.  
  111. /*******************************************************************************
  112. ** TMacSemaphore class
  113. **
  114. ** Since threads don't really exist on the Macintosh, these semaphores are
  115. ** done by shutting interrupts off to guarantee exclusivity.  Therefore,
  116. ** the rule is - never hold one very long, since on the Macintosh
  117. ** it will degrade performance if you do.
  118. ********************************************************************************/
  119.     
  120. #define kTMacSemaphoreID "!$sema,1.1"
  121.  
  122. class TMacSemaphore : public TDynamic
  123. {
  124.     public:
  125.                             MPWC TMacSemaphore();
  126.         virtual                ~ MPWC TMacSemaphore();
  127.     
  128.         virtual void        MPWC Grab();
  129.         virtual void        MPWC Release();
  130.         virtual Boolean        MPWC GrabNoWait();
  131.  
  132.     private:
  133.                             TMacSemaphore(const TMacSemaphore&);
  134.                 void        operator=(const TMacSemaphore&);
  135.  
  136.         short    fSaveLevel;
  137.         short    fCount;
  138. };
  139.  
  140. /*******************************************************************************
  141. ** CLASS TMatchObject
  142. **
  143. ** This object is the base class for any object which "knows" how
  144. ** to hash a specific object, as well as how to compare a
  145. ** 2nd object to the specific object.
  146. ********************************************************************************/
  147.  
  148. #define kTMatchObjectID "!$mobj,1.1"
  149.  
  150. class TMatchObject : public TDynamic
  151. {
  152.     public:
  153.         virtual                    ~ MPWC TMatchObject();
  154.         
  155.             // Default implementation is to return 0
  156.         virtual unsigned long    MPWC Hash() const;
  157.             // Default implementation is to compare
  158.             // address of "this" with address of the object
  159.         virtual short            MPWC Compare(const void*) const;
  160.             // Default implementation is to call Compare
  161.         virtual Boolean            MPWC IsEqual(const void*) const;
  162.  
  163.     protected:
  164.                                 TMatchObject();
  165. };
  166.  
  167. /*******************************************************************************
  168. ** CLASS TProcMatchObject
  169. **
  170. ** This is a TMatchObject which takes a reference pointer and pointers to "C"
  171. ** functions to do the matching/hashing job.
  172. ********************************************************************************/
  173.  
  174. #define kTProcMatchObjectID "!$pmob,1.1"
  175.  
  176. class TProcMatchObject : public TMatchObject
  177. {
  178.     public:
  179.                                 MPWC TProcMatchObject(const void* ref, HashProcPtr = 0,
  180.                                                       CompareProcPtr = 0, IsEqualProcPtr = 0);
  181.         virtual                    ~ MPWC TProcMatchObject();
  182.         
  183.         virtual unsigned long    MPWC Hash() const;
  184.         virtual short            MPWC Compare(const void*) const;
  185.         virtual Boolean            MPWC IsEqual(const void*) const;
  186.  
  187.                 void            SetReferencePointer(const void*);
  188.                 void            SetHashProc(HashProcPtr);
  189.                 void            SetCompareProc(CompareProcPtr);
  190.                 void            SetIsEqualProc(IsEqualProcPtr);
  191.                 
  192.                 const void*        GetReferencePointer() const;
  193.                 HashProcPtr        GetHashProc() const;
  194.                 CompareProcPtr    GetCompareProc() const;
  195.                 IsEqualProcPtr    GetIsEqualProc() const;
  196.                 
  197.     private:
  198.             const void*        fRef;
  199.             HashProcPtr        fHashProc;
  200.             CompareProcPtr    fCompareProc;
  201.             IsEqualProcPtr    fIsEqualProc;
  202. };
  203.  
  204.  
  205. /*    -------------------------------------------------------------------------
  206.     Inline methods for TProcMatchObject
  207.     ------------------------------------------------------------------------- */
  208.  
  209.     inline void TProcMatchObject::SetReferencePointer(const void* ref)
  210.     {
  211.         fRef = ref;
  212.     }
  213.  
  214.     inline void TProcMatchObject::SetHashProc(HashProcPtr proc)
  215.     {
  216.         fHashProc = proc;
  217.     }
  218.  
  219.     inline void TProcMatchObject::SetCompareProc(CompareProcPtr proc)
  220.     {
  221.         fCompareProc = proc;
  222.     }
  223.  
  224.     inline void TProcMatchObject::SetIsEqualProc(IsEqualProcPtr proc)
  225.     {
  226.         fIsEqualProc = proc;
  227.     }
  228.  
  229.     inline const void* TProcMatchObject::GetReferencePointer() const
  230.     {
  231.         return fRef;
  232.     }
  233.  
  234.     inline HashProcPtr TProcMatchObject::GetHashProc() const
  235.     {
  236.         return fHashProc;
  237.     }
  238.  
  239.     inline CompareProcPtr TProcMatchObject::GetCompareProc() const
  240.     {
  241.         return fCompareProc;
  242.     }
  243.  
  244.     inline IsEqualProcPtr TProcMatchObject::GetIsEqualProc() const
  245.     {
  246.         return fIsEqualProc;
  247.     }
  248.  
  249. /*******************************************************************************
  250. ** CLASS THashObject
  251. **
  252. ** This object is the base class for any object which "knows" how
  253. ** to hash another object.
  254. ********************************************************************************/
  255.  
  256. #define kTHashObjectID "!$hobj,1.1"
  257.  
  258. class THashObject : public TDynamic
  259. {
  260.     public:
  261.         virtual                    ~ MPWC THashObject();
  262.         
  263.         virtual    unsigned long    MPWC Hash(const void*) const    = 0;
  264.  
  265.     protected:
  266.                                 MPWC THashObject();
  267. };
  268.  
  269. /*******************************************************************************
  270. ** CLASS TProcHashObject
  271. **
  272. ** This is a THashObject which uses a "C" Procedure to hash objects. 
  273. ********************************************************************************/
  274.  
  275. #define kTProcHashObjectID "!$phob,1.1"
  276.  
  277. class TProcHashObject : public THashObject
  278. {
  279.     public:
  280.                                 MPWC TProcHashObject(HashProcPtr);
  281.         virtual                    ~ MPWC TProcHashObject();
  282.         
  283.         virtual    unsigned long    MPWC Hash(const void*) const;
  284.  
  285.                 void            SetHashProc(HashProcPtr);
  286.                 HashProcPtr        GetHashProc() const;
  287.                 
  288.     private:
  289.         HashProcPtr    fHashProc;
  290. };
  291.  
  292. /*    -------------------------------------------------------------------------
  293.     Inline methods for TProcHashObject
  294.     ------------------------------------------------------------------------- */
  295.  
  296.     inline void TProcHashObject::SetHashProc(HashProcPtr proc)
  297.     {
  298.         fHashProc = proc;
  299.     }
  300.     
  301.     inline HashProcPtr TProcHashObject::GetHashProc() const
  302.     {
  303.         return fHashProc;
  304.     }
  305.     
  306. /*******************************************************************************
  307. ** CLASS TIterator
  308. **
  309. ** This class Iterates through a collection of objects.  Since
  310. ** collections are "thread-safe", when the Next() method returns
  311. ** NULL, call IterationComplete().  If it returns true, then you were
  312. ** returned NULL because the iterator was done.  Otherwise, you were
  313. ** returned NULL because the underlying collection changed.  
  314. ** RemoveCurrentObject will return false if the collection changed
  315. ** before the remove could be done.
  316. ********************************************************************************/
  317.  
  318. #define kTIteratorID "!$iter,1.1"
  319.  
  320. class TIterator : public TDynamic
  321. {
  322.     public:
  323.         virtual                    ~ MPWC TIterator();
  324.         
  325.         virtual    void            MPWC Reset()                    = 0;
  326.         virtual void*            MPWC Next()                        = 0;
  327.         
  328.         virtual Boolean            MPWC IterationComplete() const    = 0;
  329.         virtual Boolean            MPWC RemoveCurrentObject()        = 0;
  330.         
  331.                 void             SetMatchObject(TMatchObject*);
  332.                 TMatchObject*     GetMatchObject() const;
  333.  
  334.     protected:
  335.                                 MPWC TIterator();
  336.                                 
  337.     private:
  338.         TMatchObject*        fMatcher;
  339. };
  340.  
  341. /*    -------------------------------------------------------------------------
  342.     Inline methods for TIterator
  343.     ------------------------------------------------------------------------- */
  344.     
  345.     inline void TIterator::SetMatchObject(TMatchObject* theMatcher)
  346.     {
  347.         fMatcher = theMatcher;
  348.     }
  349.     
  350.     inline TMatchObject* TIterator::GetMatchObject() const
  351.     {
  352.         return fMatcher;
  353.     }
  354.  
  355. /*******************************************************************************
  356. ** CLASS TCollection
  357. **
  358. ** This class defines the framework for all collections.
  359. ********************************************************************************/
  360.  
  361. #define kTCollectionID "!$coll,1.1"
  362.  
  363. class TCollection : public TDynamic
  364. {
  365.     public:
  366.         virtual                ~ MPWC TCollection();
  367.         
  368.                 size_t        Count() const;
  369.                 Boolean        IsEmpty() const;
  370.         virtual TIterator*    MPWC CreateIterator(TStandardPool*)             = 0;
  371.         
  372.         virtual OSErr        MPWC Add(void*);
  373.         virtual OSErr        MPWC AddUnique(void*, const TMatchObject&);
  374.         virtual OSErr        MPWC AddUnique(void*);
  375.                 
  376.         virtual void        MPWC RemoveAll();
  377.         virtual void        MPWC DeleteAll(PointerType = kTDynamicPointer);    
  378.         virtual void*        MPWC Remove(const TMatchObject&)                = 0;
  379.         virtual void*        MPWC Member(const TMatchObject&)                = 0;
  380.         virtual Boolean        MPWC Remove(void*)                                = 0;
  381.         virtual Boolean        MPWC Member(const void*)                        = 0;
  382.         
  383.         virtual void*        MPWC GetIndexedObject(size_t) const;
  384.                 void*        operator[](size_t);
  385.  
  386.                 long        GetSeed() const;
  387.                 void        Grab();
  388.                 void        Release();
  389.     
  390.     protected:
  391.                             MPWC TCollection();
  392.         virtual OSErr        MPWC PrivateAdd(void*, long)                    = 0;
  393.         virtual void        MPWC KillAll(BooleanParm ifDel, PointerType)    = 0;
  394.  
  395.         long            fSeed;
  396.         size_t            fCount;
  397.         TMacSemaphore    fSemaphore;
  398. };
  399.  
  400. /*    -----------------------------------------------------------------
  401.     Inline Methods for TCollection
  402.     ----------------------------------------------------------------- */
  403.  
  404.     inline size_t TCollection::Count() const
  405.     {
  406.         return fCount;
  407.     }
  408.  
  409.     inline Boolean TCollection::IsEmpty() const
  410.     {
  411.         return fCount == 0;
  412.     }
  413.  
  414.     inline void* TCollection::operator[](size_t idx)
  415.     {
  416.         return GetIndexedObject(idx);
  417.     }
  418.  
  419.     inline long TCollection::GetSeed() const
  420.     {
  421.         return fSeed;
  422.     }
  423.     
  424.     inline void TCollection::Grab()
  425.     {
  426.         (&fSemaphore)->Grab();
  427.     }
  428.     
  429.     inline void TCollection::Release()
  430.     {
  431.         (&fSemaphore)->Release();
  432.     }
  433.     
  434. /*******************************************************************************
  435. ** CLASS TLink
  436. **
  437. ** This class implements a link object which can be placed on a linked
  438. ** list.  It is totally non-virtual since it is a trivial class and
  439. ** to keep it at 8 bytes in size.
  440. ********************************************************************************/
  441.  
  442. class TLink
  443. {
  444.     public:
  445.                         TLink(void* value);
  446.                         TLink(TLink* link, void* value);
  447.                         TLink(BooleanParm);
  448.                         TLink();
  449.                         ~TLink();
  450.                         
  451.         void*            operator new(size_t size, TMemoryPool*);    // default size, from a pool
  452.         void*            operator new(size_t);                        // from default pool
  453.         void            operator delete(void* mem) {SLMDeleteOperator(mem);};
  454.         
  455.         void            SetNext(TLink* link);
  456.         TLink*            GetNext() const;
  457.         
  458.         void*            GetValue() const;
  459.         void            SetValue(void*);
  460.         
  461.         void            Append(TLink* newLink);        // append newLink after this
  462.         void            Remove(TLink* previous);    // remove nextLink from list
  463.  
  464.     private:
  465.         TLink*        fNext;
  466.         void*        fValue;
  467. };
  468.  
  469. /*    -----------------------------------------------------------------
  470.     Inline Methods for TLink
  471.     ----------------------------------------------------------------- */
  472.     
  473.     inline void* TLink::operator new(size_t size, TMemoryPool* thePool)
  474.     {
  475.         return SLMNewOperator(size, thePool);
  476.     }
  477.     
  478.     inline void* TLink::operator new(size_t size)
  479.     {
  480.         return SLMNewOperator(size, NULL);
  481.     }
  482.  
  483.     inline TLink::TLink(BooleanParm)
  484.     {}
  485.     
  486.     inline TLink::TLink()
  487.     {
  488.         fNext    = NULL;
  489.         fValue    = NULL;
  490.     }
  491.     
  492.     inline TLink::TLink(void* value)
  493.     {
  494.         fNext    = NULL;
  495.         fValue    = value;
  496.     }
  497.     
  498.     inline TLink::TLink(TLink* link, void* value)
  499.     {
  500.         fNext    = link;
  501.         fValue    = value;
  502.     }
  503.     
  504.     inline TLink::~TLink()
  505.     {
  506.         fNext    = NULL;
  507.         fValue    = NULL;
  508.     }
  509.     
  510.     inline void TLink::SetNext(TLink* link)
  511.     {
  512.         fNext = link;
  513.     }
  514.         
  515.     inline TLink* TLink::GetNext() const
  516.     {
  517.         return fNext;
  518.     }
  519.         
  520.     inline void* TLink::GetValue() const
  521.     {
  522.         return fValue;
  523.     }
  524.     
  525.     inline void TLink::SetValue(void* obj) 
  526.     {
  527.         fValue = obj;
  528.     }
  529.     
  530.     inline void TLink::Append(TLink* newLink)
  531.     {
  532.         newLink->SetNext(fNext);
  533.         fNext = newLink;
  534.     }
  535.     
  536.     inline void TLink::Remove(TLink* previous)
  537.     {
  538.         TLink* link = previous->GetNext();
  539.         previous->SetNext(fNext);
  540.         link->SetNext(NULL);
  541.     }
  542.     
  543. /*******************************************************************************
  544. ** CLASS TPriorityLink
  545. **
  546. ** This class implements a link object which can be placed on a linked
  547. ** list, and can hold a timer or priority value.
  548. ********************************************************************************/
  549.  
  550. #define kNormalPriority        (((unsigned long)-1L) >> 1)
  551. #define kHighestPriority    0
  552. #define kLowestPriority        ((unsigned long)-1L)
  553. #define kToLowerPriority    1
  554.  
  555. class TPriorityLink : public TLink
  556. {
  557.     public:
  558.                         TPriorityLink(BooleanParm);
  559.                         TPriorityLink(void* value);
  560.                         TPriorityLink(TLink* link, void* value);
  561.                         TPriorityLink();
  562.                         
  563.         void            SetPriority(unsigned long);
  564.         unsigned long    GetPriority() const;
  565.     
  566.     private:
  567.         unsigned long    fPriority;
  568. };
  569.  
  570. /*    -----------------------------------------------------------------
  571.     Inline Methods for TPriorityLink
  572.     ----------------------------------------------------------------- */
  573.     
  574.     inline TPriorityLink::TPriorityLink(BooleanParm val) : TLink(val)
  575.     {}
  576.     
  577.     inline TPriorityLink::TPriorityLink()
  578.     {
  579.         fPriority = kNormalPriority;
  580.     }
  581.     
  582.     inline TPriorityLink::TPriorityLink(TLink* link, void* value) : 
  583.         TLink(link, value)
  584.     {
  585.         fPriority = kNormalPriority;
  586.     }
  587.     
  588.     inline TPriorityLink::TPriorityLink(void* value) : TLink(value)
  589.     {
  590.         fPriority = kNormalPriority;
  591.     }
  592.     
  593.     inline void TPriorityLink::SetPriority(unsigned long pri)
  594.     {
  595.         fPriority = pri;
  596.     }
  597.         
  598.     inline unsigned long TPriorityLink::GetPriority() const
  599.     {
  600.         return fPriority;
  601.     }
  602.     
  603. /*******************************************************************************
  604. ** CLASS TSimpleList
  605. **
  606. ** This class implements a simple linked list, which can have objects added
  607. ** at the front or the back of the list.
  608. ********************************************************************************/
  609.  
  610. #define kTSimpleListID "!$slst,1.1"
  611.  
  612. class TSimpleList : public TCollection
  613. {
  614.     friend class    TListIterator;
  615.  
  616.     public:
  617.                                 MPWC TSimpleList();
  618.                                 MPWC TSimpleList(TMemoryPool*);
  619.                                 MPWC TSimpleList(TSimpleList*);
  620.         virtual                    ~ MPWC TSimpleList();
  621.     
  622.         // TCollection overrides
  623.         
  624.         virtual TIterator*        MPWC CreateIterator(TStandardPool*);
  625.         
  626.         virtual void*            MPWC Remove(const TMatchObject&);
  627.         virtual void*            MPWC Member(const TMatchObject&);
  628.         virtual Boolean            MPWC Remove(void*);
  629.         virtual Boolean            MPWC Member(const void*);
  630.         
  631.         // New methods
  632.         
  633.         virtual TLink*            MPWC MemberLink(const void*);
  634.         virtual TLink*            MPWC MemberLink(const TMatchObject&);
  635.         virtual TLink*            MPWC RemoveLink(void*);
  636.         virtual TLink*            MPWC RemoveLink(const TMatchObject&);
  637.  
  638.         virtual TLink*            MPWC FirstLink() const;
  639.         virtual TLink*            MPWC LastLink() const;
  640.         virtual    TLink*            MPWC RemoveFirstLink();
  641.         virtual    TLink*            MPWC RemoveLastLink();
  642.         virtual    void            MPWC AddLinkFirst(TLink*);
  643.         virtual    void            MPWC AddLinkLast(TLink*);
  644.  
  645.         virtual    void*            MPWC First() const;
  646.         virtual    void*            MPWC Last() const;
  647.         virtual    void*            MPWC RemoveFirst();
  648.         virtual    void*            MPWC RemoveLast();
  649.         virtual    OSErr            MPWC AddFirst(void*);
  650.         virtual    OSErr            MPWC AddLast(void*);
  651.         
  652.                 void            SetLinkPool(TMemoryPool*);
  653.                 TMemoryPool*    GetLinkPool() const;
  654.  
  655.     protected:
  656.         virtual OSErr            MPWC PrivateAdd(void*, long);
  657.         virtual void            MPWC KillAll(BooleanParm ifDel, PointerType);
  658.         virtual TLink*            MPWC PrivateFind(const void*, const TMatchObject*, TLink**) const;
  659.  
  660.     private:
  661.                                 TSimpleList(const TSimpleList&);
  662.                 void            operator=(const TSimpleList&);
  663.         
  664.     protected:
  665.     
  666.         TLink*            fList;
  667.         TLink*            fLastInList;
  668.         TMemoryPool*    fLinkPool;
  669. };
  670.  
  671. /*    -----------------------------------------------------------------
  672.     Inline Methods for TSimpleList
  673.     ----------------------------------------------------------------- */
  674.     
  675.     inline void TSimpleList::SetLinkPool(TMemoryPool* thePool)
  676.     {
  677.         fLinkPool = thePool;
  678.     }
  679.  
  680.     inline TMemoryPool* TSimpleList::GetLinkPool() const
  681.     {
  682.         return fLinkPool;
  683.     }
  684.  
  685. /*******************************************************************************
  686. ** CLASS TLinkedList
  687. **
  688. ** This class adds the ability to do things with a linked list based on
  689. ** "after" or "before" rules.
  690. ********************************************************************************/
  691.  
  692. #define kTLinkedListID "slm:coll$llst,1.1"
  693.  
  694. class TLinkedList : public TSimpleList
  695. {
  696.     public:
  697.                                 MPWC TLinkedList();
  698.                                 MPWC TLinkedList(TMemoryPool*);
  699.                                 MPWC TLinkedList(TSimpleList*);
  700.         virtual                    ~ MPWC TLinkedList();
  701.             
  702.         // New methods
  703.                 
  704.         virtual    void*            MPWC After(const void* obj) const;
  705.         virtual    void*            MPWC After(const TMatchObject&) const;
  706.         virtual    void*            MPWC Before(const void* obj) const;
  707.         virtual    void*            MPWC Before(const TMatchObject&) const;
  708.         
  709.         virtual Boolean            MPWC AddLinkAfter(TLink*, const TMatchObject&);
  710.         virtual Boolean            MPWC AddLinkAfter(TLink*, const void* obj);
  711.         virtual Boolean            MPWC AddLinkBefore(TLink*, const TMatchObject&);
  712.         virtual Boolean            MPWC AddLinkBefore(TLink*, const void* obj);
  713.         virtual OSErr            MPWC AddAfter(void*, const TMatchObject&);
  714.         virtual OSErr            MPWC AddAfter(void*, const void* obj);
  715.         virtual OSErr            MPWC AddBefore(void*, const TMatchObject&);
  716.         virtual OSErr            MPWC AddBefore(void*, const void* obj);
  717.  
  718.     private:
  719.                                 TLinkedList(const TLinkedList&);
  720.                 void            operator=(const TLinkedList&);
  721. };
  722.  
  723. /*******************************************************************************
  724. ** CLASS TPriorityList
  725. **
  726. ** This class implements a list where objects are sorted in order of a 
  727. ** priority.
  728. ********************************************************************************/
  729.  
  730. #define kTPriorityListID "!$plst,1.1"
  731.  
  732. class TPriorityList : public TSimpleList
  733. {
  734.     public:
  735.                                 MPWC TPriorityList();
  736.                                 MPWC TPriorityList(TMemoryPool*);
  737.                                 MPWC TPriorityList(TPriorityList*);
  738.         virtual                    ~ MPWC TPriorityList();
  739.     
  740.         // TLinkedList overrides
  741.         
  742.         virtual    OSErr            MPWC AddFirst(void*);
  743.         virtual    OSErr            MPWC AddLast(void*);
  744.         virtual    void            MPWC AddLinkFirst(TLink*);
  745.         virtual    void            MPWC AddLinkLast(TLink*);
  746.         
  747.         // New methods
  748.         
  749.         virtual    OSErr            MPWC AddPrioritized(void*, unsigned long pri);
  750.         virtual    void            MPWC AddLink(TPriorityLink*);
  751.  
  752.     private:
  753.                                 TPriorityList(const TPriorityList&);
  754.                 void            operator=(const TPriorityList&);
  755.         virtual OSErr            MPWC PrivateAdd(void*, long);
  756. };
  757.     
  758. /*******************************************************************************
  759. ** CLASS TListIterator
  760. **
  761. ** This iterator is used to iterate all collection classes descending from
  762. ** TSimpleList.
  763. ********************************************************************************/
  764.  
  765. #define kTListIteratorID "!$litr,1.1"
  766.  
  767. class TListIterator : public TIterator
  768. {
  769.     public:
  770.                             MPWC TListIterator(TSimpleList*);
  771.         virtual                ~ MPWC TListIterator();
  772.  
  773.         // TIterator Overrides
  774.         
  775.         virtual    void        MPWC Reset();
  776.         virtual void*        MPWC Next();
  777.                 
  778.         virtual Boolean        MPWC IterationComplete() const;
  779.         virtual Boolean        MPWC RemoveCurrentObject();
  780.         
  781.         // New methods
  782.         
  783.         virtual TLink*        MPWC GetCurrentLink() const;
  784.                 void        SetList(TSimpleList*);
  785.                 
  786.     private:
  787.                             TListIterator(const TListIterator&);
  788.                 void        operator=(const TListIterator&);
  789.  
  790.         virtual    TLink*        MPWC NextLink();
  791.                 
  792.         TSimpleList*    fList;
  793.         TLink*            fPrevLink;
  794.         TLink*            fCurLink;
  795.         long            fSeed;
  796.         Boolean            fComplete;
  797.         Boolean            fFiller;
  798. };
  799.  
  800. /*    -------------------------------------------------------------------------
  801.     Inline methods for TListIterator
  802.     ------------------------------------------------------------------------- */
  803.  
  804.     inline void TListIterator::SetList(TSimpleList* list)
  805.     {
  806.         fList = list;
  807.         Reset();
  808.     }
  809.  
  810. /*******************************************************************************
  811. ** CLASS TArray
  812. **
  813. ** This class implements an array collection, where objects can be efficiently
  814. ** looked at by index, and are added to the end of the array.  Deleting objects
  815. ** moves all higher-indexed objects down by 1 index number.
  816. ********************************************************************************/
  817.  
  818. #define kTArrayID "slm:coll$arry,1.1"
  819.  
  820. class TArray : public TCollection
  821. {
  822.     friend class    TArrayIterator;
  823.  
  824.     public:
  825.                                 MPWC TArray();
  826.                                 MPWC TArray(size_t size, TStandardPool* = NULL, 
  827.                                             int growBy = 0);
  828.         virtual                    ~ MPWC TArray();
  829.  
  830.         virtual Boolean            MPWC IsValid() const;
  831.                 
  832.                  TStandardPool*    GetGrowPool() const;
  833.                 
  834.         // TCollection overrides
  835.         
  836.         virtual TIterator*        MPWC CreateIterator(TStandardPool*);
  837.         
  838.         virtual Boolean            MPWC Remove(void*);
  839.         virtual void*            MPWC Remove(const TMatchObject&);
  840.         virtual Boolean            MPWC Member(const void*);
  841.         virtual void*            MPWC Member(const TMatchObject&);
  842.         
  843.         virtual void*            MPWC GetIndexedObject(size_t) const;
  844.         
  845.     private:
  846.                                 TArray(const TArray&);
  847.                 void            operator=(const TArray&);
  848.                 void            MPWC InitArray(size_t size, TStandardPool*, int growBy);
  849.         
  850.     protected:
  851.         virtual void*            MPWC MemberIndex(const void*, const TMatchObject*, size_t*);
  852.         virtual void*            MPWC PrivateRemove(void*, const TMatchObject*);
  853.         virtual OSErr            MPWC PrivateAdd(void*, long);
  854.         virtual void            MPWC KillAll(BooleanParm ifDel, PointerType);
  855.         virtual Boolean            MPWC Grow();
  856.  
  857.         void**            fArray;        // memory allocated for the array
  858.         size_t            fSize;        // current size of the array
  859.         long            fGrowBy;    // size to grow by if array is full
  860. };
  861.     
  862. /*******************************************************************************
  863. ** CLASS TArrayIterator
  864. **
  865. ** This class Iterates through a TArray collection
  866. ********************************************************************************/
  867.  
  868. #define kTArrayIteratorID "slm:coll$aitr,1.1"
  869.  
  870. class TArrayIterator : public TIterator
  871. {
  872.     public:
  873.                             MPWC TArrayIterator(TArray*);
  874.         virtual                ~ MPWC TArrayIterator();
  875.         
  876.         virtual    void        MPWC Reset();
  877.         virtual void*        MPWC Next();
  878.         
  879.         virtual Boolean        MPWC IterationComplete() const;
  880.         virtual Boolean        MPWC RemoveCurrentObject();
  881.  
  882.     private:
  883.                             TArrayIterator(const TArrayIterator&);
  884.                 void        operator=(const TArrayIterator&);
  885.  
  886.     private:
  887.         TArray*        fArray;
  888.         size_t        fCurIdx;
  889.         long        fSeed;
  890.         Boolean        fComplete;
  891.         Boolean        fFiller;
  892. };
  893.  
  894. /*******************************************************************************
  895. ** Class THashList
  896. ********************************************************************************/
  897.  
  898. #define kTHashListID    "!$hsls,1.1"
  899.  
  900. struct HashListInfo
  901. {
  902.     size_t    emptySlots;        // number of empty slots in the hash list
  903.     size_t    singleSlots;    // number of slots with only one entry
  904.     size_t    numChains;        // number of slots with more than one entry
  905.     size_t    longestChain;    // the longest chain
  906.     size_t    avgChain;        // the average length of a chain
  907. };
  908.  
  909. class THashList : public TCollection
  910. {
  911.     friend class    THashListIterator;
  912.     
  913.     protected:
  914.                                     MPWC THashList(BooleanParm);
  915.                                     
  916.     public:
  917.                                     MPWC THashList();
  918.                                     MPWC THashList(THashObject*,
  919.                                                    size_t initialSize,
  920.                                                    TMemoryPool* = NULL);
  921.         virtual                        ~ MPWC THashList();
  922.  
  923.         virtual Boolean                MPWC IsValid() const;
  924.         
  925.         virtual OSErr                MPWC Grow(size_t newSize);
  926.         
  927.                 OSErr                Rehash();
  928.                 
  929.                 void                SetHashObject(THashObject*);
  930.                 TMemoryPool*        GetLinkPool() const;
  931.                 THashObject*        GetHashObject() const;
  932.                 size_t                GetTableSize() const;
  933.                 void                SetLinkPool(TMemoryPool*);
  934.         
  935.         virtual void                MPWC GetHashListInfo(HashListInfo&) const;
  936.         
  937.         // TCollection Overrides
  938.         
  939.         virtual TIterator*            MPWC CreateIterator(TStandardPool*);
  940.     
  941.         virtual void*                MPWC Remove(const TMatchObject&);
  942.         virtual void*                MPWC Member(const TMatchObject&);
  943.         virtual Boolean                MPWC Remove(void*);
  944.         virtual Boolean                MPWC Member(const void*);
  945.         
  946.     protected:
  947.         virtual OSErr                MPWC PrivateAdd(void*, long);
  948.         virtual void                MPWC KillAll(BooleanParm ifDel, PointerType);
  949.  
  950.         virtual void*                MPWC PrivateFind(const void*,
  951.                                                      const TMatchObject*,
  952.                                                      void** toDel);
  953.                                         
  954.         virtual Boolean                MPWC IsPrime(size_t num);           
  955.         virtual size_t                MPWC FixSize(size_t);
  956.                 unsigned long        Hash(const void*);
  957.                  
  958.     private:
  959.                                     THashList(const THashList&);
  960.                 void                operator=(const THashList&);
  961.                 void                MPWC InitHashList(THashObject*, TMemoryPool*,
  962.                                                       size_t);
  963.     protected:        
  964.         THashObject*        fHasher;
  965.         TMemoryPool*        fLinkPool;
  966.         void**                fTable;
  967.         size_t                fTableSize;
  968.         void**                fGrowTable;
  969.         size_t                fGrowTableSize;
  970.         Boolean                fGrowInProgress;
  971.         Boolean                fFiller;
  972. };
  973.  
  974. /*    -------------------------------------------------------------------------
  975.     Inline methods for THashList
  976.     ------------------------------------------------------------------------- */
  977.  
  978.     inline void THashList::SetHashObject(THashObject* obj)
  979.     {
  980.         fHasher = obj;
  981.     }
  982.     
  983.     inline THashObject* THashList::GetHashObject() const
  984.     {
  985.         return fHasher;
  986.     }
  987.     
  988.     inline void THashList::SetLinkPool(TMemoryPool* pool)
  989.     {
  990.         fLinkPool = pool;
  991.     }
  992.     
  993.     inline TMemoryPool* THashList::GetLinkPool() const
  994.     {
  995.         return fLinkPool;
  996.     }
  997.     
  998.     inline size_t THashList::GetTableSize() const
  999.     {
  1000.         return fTableSize;
  1001.     }
  1002.     
  1003.     inline OSErr THashList::Rehash()
  1004.     {
  1005.         return Grow(GetTableSize());
  1006.     }
  1007.  
  1008. /*******************************************************************************
  1009. ** CLASS THashListIterator
  1010. ********************************************************************************/
  1011.  
  1012. #define kTHashListIteratorID "!$hsit,1.1"
  1013.  
  1014. class THashListIterator : public TIterator
  1015. {
  1016.     public:
  1017.                             MPWC THashListIterator(THashList*,
  1018.                                                     TMatchObject* = NULL);
  1019.         virtual                ~ MPWC THashListIterator();
  1020.         
  1021.         // TIterator Overrides
  1022.         
  1023.         virtual void        MPWC Reset();
  1024.         virtual void*        MPWC Next();
  1025.     
  1026.         virtual Boolean        MPWC IterationComplete() const;
  1027.         virtual Boolean        MPWC RemoveCurrentObject();
  1028.  
  1029.     protected:        
  1030.         virtual Boolean        MPWC SetNextTable(int);
  1031.         
  1032.     private:
  1033.                             THashListIterator (const THashListIterator&);
  1034.                 void        operator=(const THashListIterator&);
  1035.         
  1036.     protected:
  1037.         THashList*            fList;
  1038.         long                fSeed;
  1039.         void**                fTable;
  1040.         size_t                fTableSize;
  1041.         TLink*                fLink;
  1042.         size_t                fCell;
  1043.         short                fTableNo;
  1044.         Boolean                fFirst;
  1045.         Boolean                fComplete;
  1046. };
  1047.  
  1048. /*******************************************************************************
  1049. ** CLASS TOperation
  1050. *******************************************************************************/
  1051.  
  1052. #define kTOperationID    "!$oper,1.1"
  1053.  
  1054. #define kRemovedInProcess ((TPriorityLink*)-1L)
  1055.  
  1056. class TOperation : public TDynamic
  1057. {
  1058.     public:
  1059.                                 MPWC TOperation();
  1060.                                 MPWC TOperation(long creatorData);
  1061.                                 MPWC TOperation(void* creatorPtr);
  1062.                                 MPWC TOperation(ProcessProcPtr, long creatorData);
  1063.                                 MPWC TOperation(ProcessProcPtr, void* creatorPtr);
  1064.                                 MPWC TOperation(const TOperation&);
  1065.         virtual                    ~ MPWC TOperation();
  1066.         
  1067.                 TPriorityLink*    GetLink();
  1068.                 
  1069.         virtual void            MPWC Reset();
  1070.         virtual void            MPWC Process();
  1071.  
  1072.                 Boolean            WasRemovedInProcess() const;
  1073.                 void            ClearRemovedInProcess();
  1074.                 void            SetDeleteWhenDone();
  1075.                 Boolean            IsBeingRerun() const;
  1076.         
  1077.                 void            SetProcessProc(ProcessProcPtr);
  1078.                 ProcessProcPtr    GetProcessProc() const;
  1079.  
  1080.                 // Timer and Priority are just 2 different ways
  1081.                 // of looking at the same field.
  1082.                 
  1083.                 void            SetTime(const TTime&);
  1084.                 void            SetTime(unsigned long msecs);
  1085.                 void            SetPriority(unsigned long pri);
  1086.                 unsigned long    GetTime() const;
  1087.                 unsigned long    GetPriority() const;
  1088.  
  1089.                 // CreatorData and CreatorPtr are just 2 different ways
  1090.                 // of looking at the same field.
  1091.                 
  1092.                 void*            GetCreatorPtr() const;
  1093.                 long            GetCreatorData() const;
  1094.                 void            SetCreatorPtr(void*);
  1095.                 void            SetCreatorData(long);
  1096.                 
  1097.                 GlobalWorld        GetSavedGlobalWorld() const;
  1098.                 void            SetSavedGlobalWorld(GlobalWorld);
  1099.         
  1100.     private:
  1101.         
  1102.         ProcessProcPtr            fProc;
  1103.         union
  1104.         {
  1105.             void*        fPtr;
  1106.             long        fLong;
  1107.         }                        fCreatorData;            // Storage for the Creator
  1108.         TPriorityLink            fProcessLink;
  1109.         GlobalWorld                fSavedWorld;
  1110. };
  1111.  
  1112. /*    -----------------------------------------------------------------
  1113.     Inline Methods for TOperation
  1114.     ----------------------------------------------------------------- */
  1115.     
  1116.     inline TPriorityLink* TOperation::GetLink()
  1117.     {
  1118.         return &fProcessLink;
  1119.     }
  1120.     
  1121.     inline Boolean TOperation::WasRemovedInProcess() const
  1122.     {
  1123.         return fProcessLink.GetNext() == kRemovedInProcess;
  1124.     }
  1125.     
  1126.     inline void TOperation::ClearRemovedInProcess()
  1127.     {
  1128.         fProcessLink.SetNext(NULL);
  1129.     }
  1130.     
  1131.     inline Boolean TOperation::IsBeingRerun() const
  1132.     {
  1133.         return fProcessLink.GetPriority() != 0;
  1134.     }
  1135.     
  1136.     inline void TOperation::SetDeleteWhenDone()
  1137.     {
  1138.         fProcessLink.SetNext(kRemovedInProcess);
  1139.     }
  1140.     
  1141.     inline unsigned long TOperation::GetTime() const
  1142.     {
  1143.         return fProcessLink.GetPriority();
  1144.     }
  1145.     
  1146.     inline unsigned long TOperation::GetPriority() const
  1147.     {
  1148.         return fProcessLink.GetPriority();
  1149.     }
  1150.     
  1151.     inline void TOperation::SetTime(unsigned long msec)
  1152.     {
  1153.         fProcessLink.SetPriority(msec);
  1154.     }
  1155.     
  1156.     inline void TOperation::SetProcessProc(ProcessProcPtr proc)
  1157.     {
  1158.         fProc = proc;
  1159.     }
  1160.     
  1161.     inline void TOperation::SetPriority(unsigned long pri)
  1162.     {
  1163.         fProcessLink.SetPriority(pri);
  1164.     }
  1165.     
  1166.     inline void* TOperation::GetCreatorPtr() const
  1167.     {
  1168.         return fCreatorData.fPtr;
  1169.     }
  1170.     
  1171.     inline void TOperation::SetCreatorPtr(void* data)
  1172.     {
  1173.         fCreatorData.fPtr = data;
  1174.     }
  1175.     
  1176.     inline long TOperation::GetCreatorData() const
  1177.     {
  1178.         return fCreatorData.fLong;
  1179.     }
  1180.     
  1181.     inline void TOperation::SetCreatorData(long data)
  1182.     {
  1183.         fCreatorData.fLong = data;
  1184.     }
  1185.         
  1186.     inline ProcessProcPtr TOperation::GetProcessProc() const
  1187.     {
  1188.         return fProc;
  1189.     }
  1190.         
  1191.     inline GlobalWorld TOperation::GetSavedGlobalWorld() const
  1192.     {
  1193.         return fSavedWorld;
  1194.     }
  1195.         
  1196.     inline void TOperation::SetSavedGlobalWorld(GlobalWorld world)
  1197.     {
  1198.         fSavedWorld = world;
  1199.     }
  1200.     
  1201. /*******************************************************************************
  1202. ** CLASS TScheduler
  1203. **
  1204. ** This is the base class for all schedulers.  It allows for scheduling
  1205. ** TOperations and removing them from the scheduling queue.
  1206. *******************************************************************************/
  1207.  
  1208. #define kTSchedulerID    "!$sked,1.1"
  1209.  
  1210. class TScheduler : public TDynamic
  1211. {
  1212.     protected:
  1213.                             MPWC TScheduler();
  1214.                             
  1215.     public:
  1216.         virtual             ~ MPWC TScheduler();
  1217.         
  1218.         virtual Boolean        MPWC Remove(TOperation*)            = 0;
  1219.         virtual TOperation*    MPWC Remove(const TMatchObject&)    = 0;
  1220.         virtual TOperation*    MPWC RemoveNext()                    = 0;
  1221.         virtual Boolean        MPWC IsEmpty() const                = 0;
  1222.         
  1223.         virtual void        MPWC Schedule(TOperation*)            = 0;
  1224.         virtual void        MPWC Run()                            = 0;
  1225.         
  1226.                 Boolean        IsSchedulerWorldValid() const;
  1227.                 GlobalWorld    GetSchedulerWorld() const;
  1228.                 void        SetSchedulerWorld(GlobalWorld);
  1229.     protected:
  1230.         GlobalWorld            fSchedulerWorld;
  1231. };
  1232.  
  1233. /*    -------------------------------------------------------------------------
  1234.     Inline Methods for class TScheduler
  1235.     ------------------------------------------------------------------------- */
  1236.  
  1237.     inline Boolean TScheduler::IsSchedulerWorldValid() const
  1238.     {
  1239.         return fSchedulerWorld != kInvalidWorld;
  1240.     }
  1241.  
  1242.     inline GlobalWorld TScheduler::GetSchedulerWorld() const
  1243.     {
  1244.         return fSchedulerWorld;
  1245.     }
  1246.  
  1247.     inline void TScheduler::SetSchedulerWorld(GlobalWorld world)
  1248.     {
  1249.         fSchedulerWorld = world;
  1250.     }
  1251.     
  1252. /*******************************************************************************
  1253. ** CLASS TPriorityScheduler
  1254. **
  1255. ** This class implements a scheduler which simply insures processing
  1256. ** of the TOperations by Priority.
  1257. *******************************************************************************/
  1258.  
  1259. #define kTPrioritySchedulerID    "!$prsk,1.1"
  1260.  
  1261. class TPriorityScheduler : public TScheduler
  1262. {
  1263.     public:
  1264.                             MPWC TPriorityScheduler();    // autoRun default to false
  1265.                             MPWC TPriorityScheduler(BooleanParm ifAutoRun);
  1266.         virtual             ~ MPWC TPriorityScheduler();
  1267.         
  1268.         virtual Boolean        MPWC IsValid() const;
  1269.         
  1270.             // Returns non-zero if an Operation is removed
  1271.         virtual Boolean        MPWC Remove(TOperation*);
  1272.         virtual TOperation*    MPWC Remove(const TMatchObject&);
  1273.         virtual TOperation*    MPWC RemoveNext();
  1274.         virtual Boolean        MPWC IsEmpty() const;
  1275.         
  1276.             // Default implementation processes TOperations on the
  1277.             // linked list until it is empty, but insures that 2
  1278.             // threads are not doing it at the same time. In 
  1279.             // Non-AutoRun mode, anything scheduled after "Run"
  1280.             // is called will not Run until "Run" is called again.
  1281.         virtual void        MPWC Run();
  1282.         
  1283.             // Default implementation just throws the TOperation on
  1284.             // the linked list.  If 'ifAutoRun' was set, the Run
  1285.             // method is called.  Otherwise, someone must manually
  1286.             // call Run().
  1287.         virtual void        MPWC Schedule(TOperation*);
  1288.  
  1289.         virtual void        MPWC SetAutoRun(BooleanParm);
  1290.         
  1291.     protected:
  1292.                 Boolean        IsAutoRun() const;
  1293.                 Boolean        IsSchedulerDead() const;
  1294.                 void        SetSchedulerDead();
  1295.                 
  1296.         TPriorityList    fList;
  1297.         VOLATILE short    fBusy;
  1298.         VOLATILE short    fFlags;
  1299. };
  1300.  
  1301. /*    -------------------------------------------------------------------------
  1302.     Inline methods for TPriorityScheduler
  1303.     ------------------------------------------------------------------------- */
  1304.  
  1305.     inline Boolean TPriorityScheduler::IsAutoRun() const
  1306.     {
  1307.         return fFlags & 1;
  1308.     }
  1309.  
  1310.     inline Boolean TPriorityScheduler::IsSchedulerDead() const
  1311.     {
  1312.         return fFlags < 0;
  1313.     }
  1314.  
  1315.     inline void TPriorityScheduler::SetSchedulerDead()
  1316.     {
  1317.         fFlags = -1;
  1318.     }
  1319.     
  1320. /*******************************************************************************
  1321. ** CLASS TSerialScheduler
  1322. **
  1323. ** This class implements a scheduler which simply insures FIFO processing
  1324. ** of the TOperations.  It is the same as a TPriorityScheduler, but 
  1325. ** sets the priority of the TOperation to kNormalPriority before
  1326. ** scheduling.
  1327. *******************************************************************************/
  1328.  
  1329. #define kTSerialSchedulerID    "!$srsk,1.1"
  1330.  
  1331. class TSerialScheduler : public TPriorityScheduler
  1332. {
  1333.     public:
  1334.                             MPWC TSerialScheduler();    // autoRun default to false
  1335.                             MPWC TSerialScheduler(BooleanParm ifAutoRun);
  1336.         virtual             ~ MPWC TSerialScheduler();
  1337.         
  1338.         virtual void        MPWC Schedule(TOperation*);
  1339. };
  1340.  
  1341. /*******************************************************************************
  1342. ** CLASS TThreadScheduler
  1343. **
  1344. ** This class implements a lightweight 'thread' task.  In the Macintosh
  1345. ** implementation, it is a TPriorityScheduler.
  1346. *******************************************************************************/
  1347.  
  1348. #define kTThreadSchedulerID    "slm:sked$thsk,1.1"
  1349.  
  1350. class TThreadScheduler : public TPriorityScheduler
  1351. {
  1352.     public:
  1353.     
  1354.                             MPWC TThreadScheduler();
  1355.         virtual             ~ MPWC TThreadScheduler();
  1356.  
  1357.         virtual void        MPWC Schedule(TOperation*);
  1358.         
  1359.     protected:
  1360.         virtual void        MPWC Run();
  1361.         
  1362.     private:        
  1363.         void*        fData;
  1364. };
  1365.  
  1366. /*******************************************************************************
  1367. ** CLASS TTaskScheduler
  1368. **
  1369. ** This class implements a heavy-weight task which can interface to
  1370. ** the operating system.  In the Macintosh, it schedules TOperations to
  1371. ** run at System Task time.
  1372. *******************************************************************************/
  1373.  
  1374. #define kTTaskSchedulerID    "!$task,1.1"
  1375.  
  1376. class TTaskScheduler : public TPriorityScheduler
  1377. {
  1378.     public:
  1379.                             MPWC TTaskScheduler();
  1380.                             MPWC TTaskScheduler(unsigned long priority,
  1381.                                                 BooleanParm runToEmpty = false);
  1382.         virtual             ~ MPWC TTaskScheduler();
  1383.         
  1384.         virtual void        MPWC Schedule(TOperation*);
  1385.         
  1386.         virtual void        MPWC SetPriority(unsigned long);
  1387.                 void        MPWC SetRunToEmpty(Boolean);
  1388.  
  1389.     protected:
  1390.                 void        MPWC ProcessCalled();
  1391.  
  1392.         virtual void        MPWC Run();
  1393.  
  1394.     private:
  1395.                 void        MPWC InitTaskScheduler(unsigned long);
  1396.         
  1397.     protected:
  1398.         TOperation        fOperation;
  1399.         
  1400.     private:
  1401.         ProcPtr            fSystem;
  1402.         void*            fData;
  1403. };
  1404.  
  1405. /*    -------------------------------------------------------------------------
  1406.     Inline methods for TTaskScheduler
  1407.     ------------------------------------------------------------------------- */
  1408.  
  1409.     inline void TTaskScheduler::SetRunToEmpty(Boolean runToEmpty)
  1410.     {
  1411.         SetAutoRun(runToEmpty);
  1412.     }
  1413.     
  1414. /*******************************************************************************
  1415. ** CLASS TInterruptScheduler
  1416. **
  1417. ** This class is used by all interrupt service routines to process
  1418. ** incoming data.  All layers above the interrupt service routines
  1419. ** expect to be able to do any processing they want without fear of
  1420. ** interrupts being locked out.  That's what this scheduler insures.
  1421. *******************************************************************************/
  1422.  
  1423. #define kTInterruptSchedulerID    "slm:sked$insk,1.1"
  1424.  
  1425. class TInterruptScheduler : public  TPriorityScheduler
  1426. {
  1427.     public:
  1428.     
  1429.                             MPWC TInterruptScheduler();
  1430.                             MPWC TInterruptScheduler(TScheduler*, unsigned long priority);
  1431.         virtual             ~ MPWC TInterruptScheduler();
  1432.     
  1433.         virtual Boolean        MPWC IsValid() const;
  1434.         
  1435.         virtual void        MPWC Schedule(TOperation*);
  1436.     
  1437.     protected:
  1438.         virtual void        MPWC Run();
  1439.         
  1440.     private:
  1441.                 void        InitializeInterruptScheduler(TScheduler*, unsigned long);
  1442.         void*            fData;
  1443. };
  1444.  
  1445. /*******************************************************************************
  1446. ** CLASS TTimeScheduler
  1447. **
  1448. ** This class implements a scheduler which will process TOperations
  1449. ** when a requested amount of time has expired.
  1450. *******************************************************************************/
  1451.  
  1452. #define kMaxScheduledTime    ((unsigned long)-1L)
  1453.  
  1454. #define kTTimeSchedulerID    "slm:sked$skti,1.1"
  1455.  
  1456. class TTimeScheduler : public TScheduler
  1457. {
  1458.     public:
  1459.                                 MPWC TTimeScheduler();
  1460.                                 MPWC TTimeScheduler(void* data);
  1461.                                 MPWC TTimeScheduler(TScheduler*, unsigned long priority);
  1462.         virtual                 ~ MPWC TTimeScheduler();
  1463.     
  1464.         virtual Boolean            MPWC IsValid() const;
  1465.         
  1466.         virtual Boolean            MPWC Remove(TOperation*);
  1467.         virtual TOperation*        MPWC Remove(const TMatchObject&);
  1468.         virtual TOperation*        MPWC RemoveNext();
  1469.         virtual void            MPWC Schedule(TOperation*);
  1470.         virtual Boolean            MPWC IsEmpty() const;
  1471.         
  1472.         virtual Boolean            MPWC Reschedule(TOperation*, unsigned long time);
  1473.         virtual void            MPWC SetAutoReschedule(BooleanParm);
  1474.  
  1475.         virtual Boolean            MPWC DeleteInProcessOperation(TOperation* op);
  1476.         virtual Boolean            MPWC RerunInProcessOperation(TOperation* op);
  1477.         
  1478.     protected:
  1479.         virtual void            MPWC Run();
  1480.         virtual unsigned long    MPWC ProcessTimerEvent();
  1481.         virtual TOperation*        MPWC PrivateRemove(TOperation*, const TMatchObject*);
  1482.         virtual TPriorityLink*    MPWC GetNextOperation(void*);
  1483.         virtual void            MPWC ProcessOperation();
  1484.                 void*            GetData() const;
  1485.                         
  1486.     private:    
  1487.                 void            MPWC InitializeTimeScheduler(TScheduler*, unsigned long);
  1488.                 
  1489.         void*                fData;
  1490.         short                fTime;
  1491.         VOLATILE Boolean    fDead;
  1492.         VOLATILE char        fIfProcessing;
  1493.         TPriorityLink*        fList;
  1494.         TSimpleList            fReadyList;
  1495.         
  1496.     protected:
  1497.         VOLATILE long        fSeed;
  1498.         
  1499.     private:
  1500.         VOLATILE Boolean    fBusy;
  1501.         Boolean                fFiller;
  1502. };
  1503.  
  1504. /*    -------------------------------------------------------------------------
  1505.     Inline methods for TTimeScheduler
  1506.     ------------------------------------------------------------------------- */
  1507.  
  1508.     inline void* TTimeScheduler::GetData() const
  1509.     {
  1510.         return fData;
  1511.     }
  1512.     
  1513.  
  1514. /*******************************************************************************
  1515. ** CLASS TNotifier
  1516. **
  1517. ** This class and its subclasses are used for asynchronous notification
  1518. ** of events.
  1519. ********************************************************************************/
  1520.  
  1521. #define kTNotifierID "!$noti,1.1"
  1522.  
  1523. class TNotifier : public TDynamic
  1524. {
  1525.     public:
  1526.                             MPWC TNotifier();
  1527.         virtual                ~ MPWC TNotifier();
  1528.         
  1529.         virtual void        MPWC Notify(EventCode, OSErrParm = kNoError, 
  1530.                                         void* = NULL) = 0;
  1531.  
  1532.     protected:
  1533.         GlobalWorld    fWorld;    // Global world when constructed.
  1534. };
  1535.  
  1536. /*******************************************************************************
  1537. ** CLASS TProcNotifier
  1538. **
  1539. ** This class is the base class for Notifiers that call a "C" procedure
  1540. ** for notification.  If the "refPtr" is left NULL, it will be replaced
  1541. ** with a pointer to the TProcNotifier itself.
  1542. *******************************************************************************/
  1543.  
  1544. #define kTProcNotifierID "!$pnot,1.1"
  1545.  
  1546. class TProcNotifier : public TNotifier
  1547. {
  1548.     public:
  1549.                         MPWC TProcNotifier(NotifyProcPtr, void* refPtr = NULL);
  1550.                         MPWC TProcNotifier(const TProcNotifier&);
  1551.         virtual            ~ MPWC TProcNotifier();
  1552.         
  1553.         virtual void    MPWC Notify(EventCode, OSErrParm = kNoError,
  1554.                                     void* notifyData = NULL);
  1555.             
  1556.     private:
  1557.         NotifyProcPtr    fProc;
  1558.         void*            fPtr;
  1559. };
  1560.  
  1561. /*******************************************************************************
  1562. ** CLASS TMethodNotifier
  1563. **
  1564. ** This class is the base class for Notifiers that call a method in an object.
  1565. *******************************************************************************/
  1566.  
  1567. #define kTMethodNotifierID "!$mnot,1.1"
  1568.  
  1569. class TMethodNotifier : public TNotifier
  1570. {
  1571.     public:
  1572.                             MPWC TMethodNotifier(TDynamic*, NotifyMethodPtr);
  1573.                             MPWC TMethodNotifier(const TMethodNotifier&);
  1574.         virtual                ~ MPWC TMethodNotifier();
  1575.         
  1576.         virtual void        MPWC Notify(EventCode, OSErrParm = kNoError,
  1577.                                         void* notifyData = NULL);
  1578.  
  1579.                 TDynamic*    GetObject() const;
  1580.         
  1581.     private:
  1582.         TDynamic*        fObject;
  1583.         NotifyMethodPtr    fMethod;
  1584. };
  1585.     
  1586. /*    -----------------------------------------------------------------
  1587.     Inlines for TMethodNotifier
  1588.     ----------------------------------------------------------------- */
  1589.  
  1590.     inline TDynamic* TMethodNotifier::GetObject() const
  1591.     {
  1592.         return fObject;
  1593.     }
  1594.  
  1595. /*******************************************************************************
  1596. ** CLASS TMemoryPool
  1597. **
  1598. ** This is the abstract class from which memory allocators should
  1599. ** descend.
  1600. ********************************************************************************/
  1601.  
  1602. struct PoolInfo
  1603. {
  1604.     size_t    fFreeBytes;
  1605.     size_t    fLargestBlock;
  1606.     size_t    fMaxUsage;
  1607.     size_t    fCurSize;
  1608. };
  1609.  
  1610. #define kTMemoryPoolID "!$pool,1.1"
  1611.  
  1612. extern "C" void* NewPool(size_t, size_t, ZoneType, MemoryType);
  1613. extern "C" void* NewPoolWithZone(size_t, size_t, void*, MemoryType);
  1614. extern "C" void DeletePool(void*);
  1615.  
  1616. class TMemoryPool : public TDynamic
  1617. {
  1618.     public:
  1619.         virtual                 ~ MPWC TMemoryPool();
  1620.         
  1621.                 void*         operator new(size_t size, size_t poolSize, ZoneType zType,
  1622.                                           MemoryType mType = kNormalMemory)
  1623.                     { return NewPool(size, poolSize, zType, mType); }
  1624.                 void*        operator new(size_t size, size_t poolSize, void* zone,
  1625.                                          MemoryType mType = kNormalMemory)
  1626.                     { return NewPoolWithZone(size, poolSize, zone, mType); }
  1627.                 void*        operator new(size_t size)
  1628.                     { return NewPool(size, 0, kCurrentZone, kNormalMemory); }
  1629.                 void        operator delete(void* ptr)
  1630.                     { DeletePool(ptr); }
  1631.         
  1632.         virtual void*            MPWC Allocate(size_t)                = 0;
  1633.         virtual void*            MPWC Reallocate(void*, size_t)        = 0;
  1634.         virtual void            MPWC Free(void*)                    = 0;
  1635.         virtual    size_t            MPWC GetSize(void*) const            = 0;
  1636.  
  1637.         virtual Boolean            MPWC CheckPool() const                = 0;
  1638.         virtual void            MPWC GetPoolInfo(PoolInfo&) const;
  1639.         virtual    void            MPWC TracePoolInfo() const;
  1640.  
  1641.         virtual Boolean            MPWC AddMemoryToPool(size_t);
  1642.         virtual void            MPWC DownsizePool();
  1643.         virtual size_t            MPWC GetLargestBlockSize() const     = 0;
  1644.                 size_t            MPWC GetCurrentPoolSize() const;
  1645.         
  1646.                 void            SetNotifier(TPoolNotifier*);
  1647.                 TPoolNotifier*    GetNotifier() const;
  1648.                 void            SetNotifyMarks(size_t low, size_t high = (size_t)-1L);
  1649.                 
  1650.         static    TMemoryPool*    MPWC RecoverPool(void*);
  1651.         static    void*            MPWC AllocateMemory(size_t);
  1652.         static    void*            MPWC AllocateMemory(TMemoryPool*, size_t);
  1653.         static    void*            MPWC ReallocateMemory(void*, size_t);
  1654.         static    void            MPWC FreeMemory(void*);
  1655.         static    size_t            MPWC GetMemorySize(void*);
  1656.         
  1657.     protected:
  1658.                                 MPWC TMemoryPool();
  1659.         virtual Boolean            MPWC PrivateAddMemoryToPool(void*, size_t) = 0;
  1660.         virtual Boolean            MPWC RemoveBlockFromPool(void*, size_t);
  1661.         
  1662.     private:
  1663.                                 TMemoryPool(const TMemoryPool&);
  1664.                 void            operator=(const TMemoryPool&);
  1665.         
  1666.     private:
  1667.         void*            fMemList;
  1668.         
  1669.     protected:
  1670.         size_t            fSize;
  1671.         size_t            fLowMark;
  1672.         size_t            fHighMark;
  1673.         size_t            fMaxUsed;
  1674.         size_t            fCurFree;
  1675.         void*            fZone;
  1676.         unsigned char    fMemType;
  1677.         short            fFiller;
  1678.         TPoolNotifier*    fNotifier;
  1679.         unsigned long    fSeed;
  1680.         TMacSemaphore    fSemaphore;
  1681. };
  1682.  
  1683. /*    -----------------------------------------------------------------
  1684.     Inline Methods for TMemoryPool
  1685.     ----------------------------------------------------------------- */
  1686.  
  1687.     inline void TMemoryPool::SetNotifyMarks(size_t low, size_t high)
  1688.     {
  1689.         fLowMark = low;
  1690.         fHighMark= high;
  1691.     }
  1692.     
  1693.     inline TPoolNotifier* TMemoryPool::GetNotifier() const
  1694.     {
  1695.         return fNotifier;
  1696.     }
  1697.  
  1698.     inline void TMemoryPool::SetNotifier(TPoolNotifier* nt)
  1699.     {
  1700.         fNotifier = nt;
  1701.     }
  1702.  
  1703.     inline size_t TMemoryPool::GetCurrentPoolSize() const
  1704.     {
  1705.         return fSize;
  1706.     }
  1707.     
  1708.     inline void* TMemoryPool::AllocateMemory(TMemoryPool* thePool, size_t size)
  1709.     {
  1710.         return thePool->Allocate(size);
  1711.     }
  1712.     
  1713.     inline void* TMemoryPool::AllocateMemory(size_t size)
  1714.     {
  1715.         return ((TMemoryPool*)::GetDefaultPool())->Allocate(size);
  1716.     }
  1717.  
  1718. /*******************************************************************************
  1719. ** CLASS TStandardPool
  1720. **
  1721. ** The general purpose interrupt capable storage allocator.
  1722. ********************************************************************************/
  1723.  
  1724. #define kStandardPoolChunkOverhead    12
  1725.  
  1726. #define kTStandardPoolID "!$stdp,1.1"
  1727.  
  1728. class TStandardPool : public TMemoryPool
  1729. {
  1730.     public:
  1731.                                 MPWC TStandardPool();
  1732.         virtual                 ~ MPWC TStandardPool();
  1733.  
  1734.         virtual Boolean            MPWC IsValid() const;
  1735.  
  1736.         // TMemoryPool Overrides
  1737.         
  1738.         virtual void*            MPWC Allocate(size_t);
  1739.         virtual void*            MPWC Reallocate(void*, size_t);
  1740.         virtual void            MPWC Free(void*);
  1741.         virtual size_t            MPWC GetSize(void*) const;
  1742.         virtual Boolean            MPWC CheckPool() const;
  1743.         virtual size_t            MPWC GetLargestBlockSize() const;
  1744.     
  1745.     protected:
  1746.         virtual Boolean            MPWC PrivateAddMemoryToPool(void*, size_t);
  1747.         virtual Boolean            MPWC RemoveBlockFromPool(void*, size_t);
  1748.         
  1749.                                 MPWC TStandardPool(size_t objSize);
  1750.                                 
  1751.     private:
  1752.                                 TStandardPool(const TStandardPool&);
  1753.                 void            operator=(const TStandardPool&);
  1754.                 
  1755.                 void            MPWC InitStandardPool(size_t objSize);
  1756.         
  1757.                 Boolean            FreeChunks(void*, size_t);
  1758.                 void            InternalFree(void*);
  1759.                 
  1760.     protected:    
  1761.         void*            fList;
  1762.     
  1763.     private:
  1764.         void*            fChunks[12];
  1765. };
  1766.     
  1767.  
  1768. /*******************************************************************************
  1769. ** CLASS TChunkyPool
  1770. **
  1771. ** This class implements a Pool where the memory returned is always
  1772. ** the same size (a "chunk").
  1773. ********************************************************************************/
  1774.  
  1775. #define kChunkyPoolChunkOverhead    4
  1776.  
  1777. #define kTChunkyPoolID "!$chkp,1.1"
  1778.  
  1779. class TChunkyPool : public TMemoryPool
  1780. {
  1781.     public:
  1782.                                 MPWC TChunkyPool(size_t chunkSize);
  1783.         virtual                    ~ MPWC TChunkyPool();
  1784.         
  1785.         virtual Boolean            MPWC IsValid() const;
  1786.         
  1787.         // TMemoryPool Overrides
  1788.         
  1789.         virtual void*            MPWC Allocate(size_t size);
  1790.         virtual void*            MPWC Reallocate(void*, size_t);
  1791.         virtual void            MPWC Free(void*);
  1792.         virtual size_t            MPWC GetSize(void*) const;
  1793.         virtual Boolean            MPWC CheckPool() const;
  1794.         virtual size_t            MPWC GetLargestBlockSize() const;
  1795.  
  1796.     protected:        
  1797.         virtual Boolean            MPWC PrivateAddMemoryToPool(void*, size_t);
  1798.         virtual Boolean            MPWC RemoveBlockFromPool(void*, size_t);
  1799.         
  1800.     public:
  1801.         // New methods
  1802.     
  1803.                 size_t            GetChunkSize() const;
  1804.                 size_t            GetNumberOfChunks() const;
  1805.                 
  1806.     private:
  1807.                                 TChunkyPool(const TChunkyPool&);
  1808.                 void            operator=(const TChunkyPool&);
  1809.  
  1810.         size_t            fNumberOfChunks;
  1811.         size_t            fChunkSize;
  1812.         void*            fFreeList;
  1813. };
  1814.  
  1815. /*    -----------------------------------------------------------------
  1816.     Inline Methods for TChunkyPool
  1817.     ----------------------------------------------------------------- */
  1818.     
  1819.     inline size_t TChunkyPool::GetChunkSize() const
  1820.     {
  1821.         return fChunkSize;
  1822.     }
  1823.     
  1824.     inline size_t TChunkyPool::GetNumberOfChunks() const
  1825.     {
  1826.         return fNumberOfChunks;
  1827.     }
  1828.  
  1829. /*******************************************************************************
  1830. ** CLASS TGrowOperation
  1831. **
  1832. ** See TPoolNotifier below
  1833. ********************************************************************************/
  1834.  
  1835. #define kTGrowOperationID    "!$gwop,1.1"
  1836.  
  1837. class TGrowOperation : public TOperation
  1838. {
  1839.     public:
  1840.                         MPWC TGrowOperation();
  1841.         virtual            ~ MPWC TGrowOperation();
  1842.         
  1843.         virtual    void    MPWC Process();
  1844.  
  1845.         size_t        fGrowBy;
  1846.         Boolean*    fOpInUse;
  1847. };
  1848.  
  1849. /*******************************************************************************
  1850. ** CLASS TPoolNotifier
  1851. **
  1852. ** Used by TMemoryPools so they can be notified when the pool reaches a low or
  1853. ** high water mark. The TGrowOperation is not processed at interrupt time so it
  1854. ** is always safe for it to grow the pool.
  1855. ********************************************************************************/
  1856.  
  1857. #define kTPoolNotifierID    "!$plnt,1.1"
  1858.  
  1859. class TPoolNotifier : public TNotifier
  1860. {
  1861.     public:
  1862.                         MPWC TPoolNotifier(unsigned int growBy = 10, 
  1863.                                            unsigned int minGrow = 128);
  1864.         virtual            ~ MPWC TPoolNotifier();
  1865.  
  1866.         virtual void    MPWC Notify(EventCode, OSErrParm = kNoError, void* = NULL);
  1867.         virtual size_t    MPWC GrowBy(TMemoryPool*, size_t);
  1868.         
  1869.     private:
  1870.                 void    MPWC InitNotifier(unsigned int, unsigned int);
  1871.     
  1872.         TGrowOperation    fOperation;
  1873.         unsigned short    fMinSize;
  1874.         unsigned short    fGrowBy;
  1875.         Boolean            fOpInUse;
  1876.         Boolean            fFiller;
  1877. };
  1878.  
  1879. /*******************************************************************************
  1880. ** CLASS TArbitrator
  1881. *******************************************************************************/
  1882.  
  1883. #define kTArbitratorID    "!$arbt,1.1"
  1884.  
  1885. #define kRequestIDPrefix '?'
  1886. #define kRequestIDPrefixSize 1
  1887.  
  1888. typedef int    TokenRequestType;
  1889.  
  1890. #define kInvalidTokenRequest    ((TokenRequestType)0)
  1891. #define kRequestTokenRequest    ((TokenRequestType)1)
  1892. #define kExclusiveTokenRequest    ((TokenRequestType)2)
  1893. #define kSharedTokenRequest        ((TokenRequestType)3)
  1894.     
  1895. class TArbitrator : public THashObject
  1896. {
  1897.     friend class    TToken;
  1898.     public:
  1899.                                     MPWC TArbitrator(TStandardPool* = NULL,
  1900.                                                      size_t defSize = 0);
  1901.         virtual                        ~ MPWC TArbitrator();
  1902.         
  1903.         virtual OSErr                MPWC RegisterObject(const char* theID, void* theObject);
  1904.         virtual    void*                MPWC UnregisterObject(const char* theID);
  1905.         virtual void*                MPWC LookupObject(const char* theID);
  1906.  
  1907.         virtual OSErr                MPWC RegisterToken(TToken*);
  1908.         virtual TToken*                MPWC GetToken(const char* theID, TokenRequestType);
  1909.  
  1910.         virtual TRequestToken*        MPWC PassiveRequest(const char* theID, TokenRequestType,
  1911.                                                         TNotifier* = NULL,
  1912.                                                         BooleanParm registerIfFirst = false);
  1913.         virtual TRequestToken*        MPWC ActiveRequest(const char* theID, TokenRequestType,
  1914.                                                        TNotifier* = NULL,
  1915.                                                        BooleanParm registerIfFirst = false);
  1916.         virtual TRequestToken*         MPWC GetRequest(const char* theID);
  1917.  
  1918.         virtual Boolean                MPWC NotifyOwners(TRequestToken* theRequest);
  1919.         virtual unsigned long        MPWC Hash(const void*) const;
  1920.  
  1921.         virtual TToken*                MPWC NewToken(const char* theID, void* = NULL);
  1922.  
  1923.     private: // methods
  1924.         virtual void                MPWC ReleaseToken(TToken* theToken);
  1925.         virtual TRequestToken*         MPWC NewRequestToken(const char* theID, TokenRequestType,
  1926.                                                          TNotifier* = NULL);
  1927.     public:
  1928.         virtual void                MPWC UnregisterToken(TToken*);
  1929.  
  1930.     private: // data
  1931.         TCollection*    fHashList;
  1932. };
  1933.  
  1934. /*******************************************************************************
  1935. ** Class TTokenNotification (inline methods only)
  1936. *******************************************************************************/
  1937.  
  1938. class TTokenNotification
  1939. {
  1940.     public:
  1941.                             MPWC  TTokenNotification(TToken*, TRequestToken*);
  1942.                             ~ MPWC TTokenNotification();
  1943.         TToken*                GetToken();
  1944.         TRequestToken*        GetRequestToken();
  1945.     private:
  1946.         TToken*                fToken;
  1947.         TRequestToken*        fRequestToken;
  1948. };
  1949.  
  1950. /*    -----------------------------------------------------------------
  1951.     inline methods for TTokenNotification
  1952.     ----------------------------------------------------------------- */
  1953.     
  1954.     inline TToken* TTokenNotification::GetToken()
  1955.     {
  1956.         return fToken;
  1957.     }
  1958.     
  1959.     inline TRequestToken* TTokenNotification::GetRequestToken()
  1960.     {
  1961.         return fRequestToken;
  1962.     }
  1963.     
  1964.     
  1965. /*******************************************************************************
  1966. ** CLASS TToken
  1967. *******************************************************************************/
  1968.  
  1969. #define kTTokenID    "!$tokn,1.1"
  1970.  
  1971. class TToken : public TMatchObject
  1972. {
  1973.     friend class    TArbitrator;
  1974.  
  1975.     public:
  1976.                                     MPWC TToken();
  1977.                                     MPWC TToken(const char*);
  1978.         virtual                        ~ MPWC TToken();
  1979.  
  1980.         // TMatchObject methods
  1981.  
  1982.         virtual Boolean                MPWC IsEqual(const void*) const;
  1983.         virtual unsigned long        MPWC Hash() const;
  1984.  
  1985.         // new methods
  1986.  
  1987.         virtual Boolean                MPWC Get(TokenRequestType);
  1988.         virtual void                MPWC Release();
  1989.         virtual Boolean                MPWC Request(TRequestToken*);
  1990.         virtual Boolean                MPWC Notify(TRequestToken*);
  1991.         virtual TokenRequestType    MPWC GetRequestType() const;
  1992.  
  1993.         virtual void                MPWC SetID(const char*);
  1994.                 const char*            GetID() const;
  1995.  
  1996.                 void*                GetObject() const;
  1997.                 void                SetObject(void* theObject);
  1998.  
  1999.                 TNotifier*            GetNotifier() const;
  2000.                 void                SetNotifier(TNotifier*);
  2001.         
  2002.                 long                GetUseCount() const;
  2003.  
  2004.     private:
  2005.         virtual void                MPWC ReallyRelease();
  2006.  
  2007.     protected:
  2008.         TMacSemaphore                fSemaphore;
  2009.         char*                        fID;
  2010.         void*                        fObject;
  2011.         TArbitrator*                fArbitrator;
  2012.         long                        fUseCount;
  2013.         TNotifier*                    fNotifier;
  2014. };
  2015.  
  2016. /*    -----------------------------------------------------------------
  2017.     inlines for TToken
  2018.     ----------------------------------------------------------------- */
  2019.     
  2020.     inline const char* TToken::GetID() const
  2021.     {
  2022.         return fID;
  2023.     }
  2024.     
  2025.     inline void* TToken::GetObject() const
  2026.     {
  2027.         return fObject;
  2028.     }
  2029.     
  2030.     inline void TToken::SetObject(void* theObject)
  2031.     {
  2032.         fObject = theObject;
  2033.     }
  2034.     
  2035.     inline TNotifier* TToken::GetNotifier() const
  2036.     {
  2037.         return fNotifier;
  2038.     }
  2039.     
  2040.     inline void TToken::SetNotifier(TNotifier* theNotifier)
  2041.     {
  2042.         fNotifier = theNotifier;
  2043.     }
  2044.     
  2045.     inline long TToken::GetUseCount() const
  2046.     {
  2047.         return fUseCount;
  2048.     }
  2049.  
  2050. /*******************************************************************************
  2051. ** CLASS TRequestToken 
  2052. *******************************************************************************/
  2053.  
  2054. #define kTRequestTokenID    "!$rqtk,1.1"
  2055.  
  2056. class TRequestToken : public TToken
  2057. {
  2058.     friend class     TArbitrator;
  2059.  
  2060.     public:
  2061.         virtual                        ~ MPWC TRequestToken();
  2062.  
  2063.         // TMatchObject methods
  2064.  
  2065.         virtual Boolean                MPWC IsEqual(const void*) const;
  2066.         virtual unsigned long        MPWC Hash() const;
  2067.  
  2068.         // new methods
  2069.  
  2070.         virtual Boolean                MPWC Give(TToken* theToken);
  2071.         virtual TToken*                MPWC Exchange();
  2072.         virtual void                MPWC RequestAgain();
  2073.  
  2074.         virtual    TokenRequestType    MPWC GetRequestType() const;
  2075.         virtual    void                MPWC SetRequestType(TokenRequestType);
  2076.  
  2077.                 Boolean                IsTokenRegistered() const;
  2078.  
  2079.     private:
  2080.                                     MPWC TRequestToken();
  2081.  
  2082.     private: // data
  2083.         Boolean                        fTokenRegistered;
  2084.         Boolean                        fActive;
  2085.         TokenRequestType            fRequestType;
  2086. };
  2087.  
  2088. /*    -----------------------------------------------------------------
  2089.     inlines for TRequestToken
  2090.     ----------------------------------------------------------------- */
  2091.  
  2092.     inline Boolean TRequestToken::IsTokenRegistered() const
  2093.     {
  2094.         return fTokenRegistered;
  2095.     }
  2096.     
  2097.     
  2098. /*******************************************************************************
  2099. ** class TClassInfo
  2100. ********************************************************************************/
  2101.  
  2102. #define kTClassInfoID "slm:supp$clif,1.1"
  2103.  
  2104. class TClassInfo : public TIterator
  2105. {
  2106.     friend class TLibraryManager;
  2107.  
  2108.     public:
  2109.         virtual                 ~ MPWC TClassInfo();
  2110.  
  2111.     // TIterator overrides
  2112.  
  2113.         virtual    void            MPWC Reset();
  2114.         virtual void*            MPWC Next();    // safe to cast to TClassID* or char*
  2115.  
  2116.         virtual Boolean            MPWC IterationComplete() const;
  2117.         virtual Boolean            MPWC RemoveCurrentObject();    // do nothing instead
  2118.  
  2119.     // new methods
  2120.  
  2121.                 void            SetBaseClassID(const TClassID& classID);
  2122.  
  2123.                 TClassID*        GetClassID();
  2124.         virtual    TClassID*        MPWC GetParentID(size_t idx = 0);
  2125.                 TLibrary*        GetLibrary() const;
  2126.                 TLibraryFile*    GetLibraryFile() const;
  2127.                 unsigned short    GetVersion() const;
  2128.                 unsigned short    GetMinVersion() const;
  2129.  
  2130.                 Boolean            GetNewObjectFlag() const;
  2131.                 Boolean            GetPreloadFlag() const;
  2132.                 Boolean            GetFunctionSetFlag() const;
  2133.                 size_t            GetSize() const;
  2134.  
  2135.     private:
  2136.                                 MPWC TClassInfo();
  2137.  
  2138.     private:
  2139.         TClassID                fBaseClassID;
  2140.         TClassID                fClassID;
  2141.         TLibrary*                fLibrary;
  2142.         TLibraryFile*            fLibraryFile;
  2143.         unsigned short            fVersion;            // Class version
  2144.         unsigned short            fMinVersion;        // minimum supported version
  2145.         Boolean                    fNewObjectFlag;
  2146.         Boolean                    fPreloadFlag;
  2147.         Boolean                    fFunctionSetFlag;
  2148.         Boolean                    fFiller;
  2149.         size_t                    fSize;
  2150.         TClassID                fParentID;
  2151. };
  2152.  
  2153. /*    -------------------------------------------------------------------------
  2154.     inline methods of TClassInfo
  2155.     ------------------------------------------------------------------------- */
  2156.     
  2157.     inline void TClassInfo::SetBaseClassID(const TClassID& classID)
  2158.     {
  2159.         fBaseClassID = classID;
  2160.         Reset();
  2161.     }
  2162.     
  2163.     inline TClassID* TClassInfo::GetClassID()
  2164.     {
  2165.         return &fClassID;
  2166.     }
  2167.     
  2168.     inline TLibrary* TClassInfo::GetLibrary() const
  2169.     {
  2170.         return fLibrary;
  2171.     }
  2172.     
  2173.     inline TLibraryFile* TClassInfo::GetLibraryFile() const
  2174.     {
  2175.         return fLibraryFile;
  2176.     }
  2177.     
  2178.     inline unsigned short TClassInfo::GetVersion() const
  2179.     {
  2180.         return fVersion;
  2181.     }
  2182.     
  2183.     inline unsigned short TClassInfo::GetMinVersion() const
  2184.     {
  2185.         return fMinVersion;
  2186.     }
  2187.         
  2188.     inline Boolean TClassInfo::GetNewObjectFlag() const
  2189.     {
  2190.         return fNewObjectFlag;
  2191.     }
  2192.     
  2193.     inline Boolean TClassInfo::GetPreloadFlag() const
  2194.     {
  2195.         return fPreloadFlag;
  2196.     }
  2197.     
  2198.     inline Boolean TClassInfo::GetFunctionSetFlag() const
  2199.     {
  2200.         return fFunctionSetFlag;
  2201.     }
  2202.     
  2203.     inline size_t TClassInfo::GetSize() const
  2204.     {
  2205.         return fSize;
  2206.     }
  2207.  
  2208. /**********************************************************************
  2209. ** class TFileSpec
  2210. **
  2211. ** TFileSpec is a base class for specifying the location of a library
  2212. ** file (TLibraryFile) in a file system or OS independent way. The 
  2213. ** subclasses contain the details and the base class is used to compare
  2214. ** them or to pass them around without worry about the contents.
  2215. **
  2216. ** Currently only the TMacFileSpec is supported since this is how the
  2217. ** SLM tracks library files on the Mac OS. There is a chance that in the
  2218. ** furture it may track files under System 7.0 using TFileIDFileSpec so
  2219. ** you should write your 7.0 code to handle either type. The
  2220. ** IsFileSpecTypeSupported() routine will tell you if the specified
  2221. ** TFileSpec subclass is supported.
  2222. **
  2223. ** Generally you don't need to be concerned with with TFileSpecs unless
  2224. ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
  2225. ** or TLibraryFile::GetFileSpec().
  2226. ***********************************************************************/
  2227.  
  2228. // Different types of TFileSpecs we can have.
  2229. typedef unsigned int FileSpecType;
  2230.  
  2231. #define kUnknownFileSpecType    ((FileSpecType)0)
  2232. #define kMacType                ((FileSpecType)1)
  2233. #define kFileIDType                ((FileSpecType)2)
  2234. #define kMaxFileSpecType        ((FileSpecType)255)
  2235.  
  2236. class TFileSpec;
  2237. class TMacFileSpec;
  2238. class TFileIDFileSpec;
  2239.  
  2240. extern "C" Boolean IsFileSpecTypeSupported(FileSpecType);
  2241. extern "C" Boolean CompareFileSpecs(const void* f1, const void* f2);
  2242.  
  2243. class TFileSpec
  2244. {
  2245.     public:
  2246.         void*            operator new(size_t size, TMemoryPool *thePool)
  2247.                             { return SLMNewOperator(size, thePool); }
  2248.         void*            operator new(size_t size)
  2249.                             { return SLMNewOperator(size, NULL); }
  2250.         void            operator delete(void* obj, size_t)
  2251.                             { SLMDeleteOperator(obj); }
  2252.                                     
  2253.         FileSpecType    GetType() const;
  2254.         unsigned char    GetSize() const;
  2255.     
  2256.                         // compare operators
  2257.  
  2258.         Boolean            operator==(const TFileSpec&) const;
  2259.         Boolean            operator!=(const TFileSpec&) const;
  2260.  
  2261.                         // cast operators
  2262.  
  2263.                         operator const TMacFileSpec&() const;
  2264.                         operator const TFileIDFileSpec&() const;
  2265.     
  2266.         unsigned char    fType;
  2267.         unsigned char    fSize;
  2268. };
  2269.  
  2270.     inline FileSpecType TFileSpec::GetType() const
  2271.     {
  2272.         return fType;
  2273.     }
  2274.     
  2275.     inline unsigned char TFileSpec::GetSize() const
  2276.     {
  2277.         return fSize;
  2278.     }
  2279.  
  2280.     //
  2281.     // compare operators
  2282.     //
  2283.  
  2284.     inline Boolean TFileSpec::operator==(const TFileSpec& fileSpec) const
  2285.     {
  2286.         return (CompareFileSpecs(&fileSpec, this));
  2287.     }
  2288.  
  2289.     inline Boolean TFileSpec::operator!=(const TFileSpec& fileSpec) const
  2290.     {
  2291.         return (!CompareFileSpecs(&fileSpec, this));
  2292.     }
  2293.     
  2294.     //
  2295.     //    cast operators
  2296.     //
  2297.     
  2298.     inline TFileSpec::operator const TMacFileSpec&() const
  2299.     {
  2300.         return *(const TMacFileSpec*)this;
  2301.     }
  2302.     
  2303.     inline TFileSpec::operator const TFileIDFileSpec&() const
  2304.     {
  2305.         return *(const TFileIDFileSpec*)this;
  2306.     }
  2307.  
  2308.  
  2309. /**********************************************************************
  2310. ** class TMacFileSpec
  2311. **
  2312. ** TMacFileSpec keeps track of the file by using an file name, volume
  2313. ** refNum, and directory id. When newing a TMacFileSpec, you must
  2314. ** pass the length of the file name (not including the length byte)
  2315. ** to the new operator.
  2316. ***********************************************************************/
  2317.  
  2318. extern "C" void InitMacFileSpec(TMacFileSpec *spec, int vRefNum, long parID, Str63 name);
  2319.  
  2320. class TMacFileSpec : public TFileSpec
  2321. {
  2322.     public:    
  2323.                     TMacFileSpec(const TMacFileSpec&);
  2324.                     TMacFileSpec(int vRefNum, long parID, Str63 name);
  2325.  
  2326.         void*        operator new(size_t, size_t fileNameLen, TMemoryPool *thePool = NULL)
  2327.                         {
  2328.                             return SLMNewOperator(
  2329.                                 (sizeof(TMacFileSpec) - 
  2330.                                  sizeof(Str63) + 
  2331.                                  fileNameLen+1), thePool);
  2332.                         }
  2333.         void*        operator new(size_t size)
  2334.                         { return SLMNewOperator(size, NULL); }
  2335.                         
  2336.         void        operator delete(void* obj)
  2337.                         { SLMDeleteOperator(obj); }
  2338.     
  2339.         short    fVRefNum;    // volume refNum of volume file is on
  2340.         long    fParID;        // dirID of the folder file is in
  2341.         Str63    fName;        // name of the file
  2342. };
  2343.  
  2344.     inline TMacFileSpec::TMacFileSpec(const TMacFileSpec& fileSpec)
  2345.     {
  2346.         InitMacFileSpec(this, fileSpec.fVRefNum, fileSpec.fParID, fileSpec.fName );
  2347.     }
  2348.         
  2349.     inline TMacFileSpec::TMacFileSpec(int vRefNum, long parID, Str63 name)
  2350.     {
  2351.         InitMacFileSpec(this, vRefNum, parID, name);
  2352.     }
  2353.         
  2354.  
  2355. /**********************************************************************
  2356. ** class TFileIDFileSpec
  2357. **
  2358. ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
  2359. ***********************************************************************/
  2360.  
  2361. // Some macros to make accessing fields without doing a cast easier
  2362. #define GetFileIDFromFileSpec(x)    (((const TFileIDFileSpec&)x).fFileID)
  2363. #define GetVRefNumFromFileSpec(x)    (((const TFileIDFileSpec&)x).fVRefNum)
  2364.  
  2365. extern "C" void InitFileIDFileSpec(TFileIDFileSpec *spec, int vRefNum, long fileID);
  2366.  
  2367. class TFileIDFileSpec : public TFileSpec
  2368. {
  2369.     public:
  2370.                     TFileIDFileSpec(const TFileIDFileSpec&);
  2371.                     TFileIDFileSpec(int vRefNum, long fileID);
  2372.                 
  2373.         short        fVRefNum;    // volume refNum
  2374.         long        fFileID;    // FileID 
  2375. };
  2376.  
  2377.     inline TFileIDFileSpec::TFileIDFileSpec(const TFileIDFileSpec& fileSpec)
  2378.     {
  2379.         InitFileIDFileSpec(this, GetVRefNumFromFileSpec(fileSpec),
  2380.                            GetFileIDFromFileSpec(fileSpec));
  2381.     }
  2382.     
  2383.     inline TFileIDFileSpec::TFileIDFileSpec(int vRefNum, long fileID)
  2384.     {
  2385.         InitFileIDFileSpec(this, vRefNum, fileID);
  2386.     }
  2387.     
  2388. /*******************************************************************************
  2389. ** Class TLibraryFile
  2390. **
  2391. ** Used mainly to get resources out of a library file. A "C" interface is also
  2392. ** provided in TLibraryManagerUtilities.h
  2393. *******************************************************************************/
  2394.  
  2395. #define kTLibraryFileID "!$lfil,1.1"
  2396.  
  2397. extern "C" TLibraryFile* GetLocalLibraryFile();
  2398.     
  2399. class TLibraryFile : public TDynamic 
  2400. {
  2401.     protected:
  2402.         virtual             ~ MPWC TLibraryFile();
  2403.                             MPWC TLibraryFile();
  2404.  
  2405.         // This is the old prelight/postflight that we need to keep around so 1.0
  2406.         // clients will still work. SLM 1.1 clients should never call it. Use the
  2407.         // new calls further below
  2408.         
  2409.         virtual    OSErr        MPWC OldPreflight(short& savedRefNum) = 0;
  2410.         virtual    OSErr        MPWC OldPostflight(short savedRefNum) = 0;
  2411.         
  2412.     public:
  2413.         virtual    Ptr            MPWC GetSharedResource(ResType, int theID, OSErr* = NULL) = 0;
  2414.         virtual    Ptr            MPWC GetSharedIndResource(ResType, int index, OSErr* = NULL) = 0;
  2415.         virtual    Ptr            MPWC GetSharedNamedResource(ResType, const char* name,
  2416.                                                         OSErr* = NULL) = 0;
  2417.         
  2418.         virtual    void        MPWC ReleaseSharedResource(Ptr) = 0;
  2419.         virtual long        MPWC CountSharedResources(ResType) = 0;
  2420.         
  2421.         virtual    size_t        MPWC GetSharedResourceUseCount(Ptr) const = 0;
  2422.         virtual    OSErr        MPWC GetSharedResourceInfo(Ptr, size_t* theSize = NULL,
  2423.                                                        short* theID = NULL, ResType* = NULL,
  2424.                                                        char* theName = NULL) const = 0;
  2425.  
  2426.         virtual long        MPWC GetRefNum() const = 0;
  2427.         virtual TFileSpec*    MPWC GetFileSpec() const = 0;
  2428.         
  2429.         virtual    OSErr        MPWC OpenLibraryFile() = 0;
  2430.         virtual    OSErr        MPWC CloseLibraryFile() = 0;
  2431.  
  2432.         virtual    OSErr        MPWC Preflight(long& savedRefNum) = 0;
  2433.         virtual    OSErr        MPWC Postflight(long savedRefNum) = 0;
  2434. };
  2435.  
  2436. /*******************************************************************************
  2437. ** CLASS TBitmap
  2438. *******************************************************************************/
  2439.  
  2440. #define kTBitmapID "slm:supp$bmap,1.1"
  2441.  
  2442. class TBitmap : public TDynamic
  2443. {
  2444.     public:
  2445.                                 MPWC TBitmap(size_t numBits, TMemoryPool* pool);
  2446.                                 MPWC TBitmap(void* bits, size_t nBits);
  2447.         virtual                    ~ MPWC TBitmap();
  2448.         
  2449.         virtual Boolean            MPWC IsValid() const;
  2450.         
  2451.         // NOTE: There is no ErrorChecking on these first 3 calls.
  2452.         
  2453.         virtual    Boolean            MPWC SetBit(size_t);
  2454.         virtual    Boolean            MPWC ClearBit(size_t);
  2455.         virtual    Boolean            MPWC TestBit(size_t);
  2456.                 
  2457.                 // These return -1 if no free bits
  2458.                 
  2459.         virtual    long            MPWC SetFirstClearBit();                
  2460.         virtual    long            MPWC SetFirstClearBit(size_t, size_t);
  2461.     
  2462.     private:
  2463.                 void            InitBitmap(size_t numBits, TMemoryPool* pool);
  2464.                 void            InitBitmap(void* bits, size_t nBits);
  2465.         
  2466.         unsigned char*            fBits;
  2467.         size_t                    fNumberBits;
  2468.         Boolean                    fIsNewd;
  2469.         Boolean                    fFiller;
  2470. };
  2471.  
  2472. /*******************************************************************************
  2473. ** CLASS TFastRandom
  2474. ********************************************************************************/
  2475.  
  2476. #define kTFastRandomID    "slm:supp$frnd,1.1"
  2477.  
  2478. const unsigned long    kMaxFastRandom    = 1771874;
  2479.  
  2480. class TFastRandom : public TDynamic
  2481. {
  2482.     public:
  2483.                                 MPWC TFastRandom();
  2484.                                 MPWC TFastRandom(unsigned long seed);
  2485.         virtual                    ~ MPWC TFastRandom();
  2486.         
  2487.         virtual void            MPWC SetSeed(unsigned long seed);
  2488.         virtual void            MPWC SetSeed();
  2489.                 unsigned long    GetSeed() const;
  2490.                 
  2491.         virtual unsigned long    MPWC GetRandom();
  2492.         virtual unsigned long    MPWC GetRandomNumber(unsigned long lo,
  2493.                                                      unsigned long hi);
  2494.         
  2495.     protected:
  2496.         unsigned long    fSeed;
  2497. };
  2498.  
  2499. /*    -------------------------------------------------------------------------
  2500.     Inline method for TFastRandom
  2501.     ------------------------------------------------------------------------- */
  2502.  
  2503.     inline unsigned long TFastRandom::GetSeed() const
  2504.     {
  2505.         return fSeed;
  2506.     }
  2507.     
  2508. /*******************************************************************************
  2509. ** CLASS TSimpleRandom
  2510. ********************************************************************************/
  2511.  
  2512. #define kTSimpleRandomID    "slm:supp$srnd,1.1"
  2513.  
  2514. const unsigned long    kMaxSimpleRandom    = 2145740624;
  2515.  
  2516. class TSimpleRandom : public TFastRandom
  2517. {
  2518.     public:
  2519.                                 MPWC TSimpleRandom();
  2520.                                 MPWC TSimpleRandom(unsigned long seed);
  2521.                                 MPWC TSimpleRandom(unsigned long im, unsigned long ia,
  2522.                                                    unsigned long ic);
  2523.         virtual                    ~ MPWC TSimpleRandom();
  2524.         
  2525.         virtual unsigned long    MPWC GetRandom();
  2526.         virtual unsigned long    MPWC GetRandomNumber(unsigned long lo,
  2527.                                                      unsigned long hi);
  2528.         
  2529.     protected:
  2530.         unsigned long    fIM;
  2531.         unsigned long    fIA;
  2532.         unsigned long    fIC;
  2533. };
  2534.  
  2535. /*******************************************************************************
  2536. ** CLASS TDoubleLong
  2537. **
  2538. ** Implements a TDynamic double long (64 bits).  Normally this is used
  2539. ** as a superclass for some other class which has a 64-bit value as its 
  2540. ** comparable/hashing value  (the default hash value is the low 32-bits).
  2541. *******************************************************************************/
  2542.  
  2543. #define kTDoubleLongID "slm:supp$dbll,1.1"
  2544.  
  2545. class TDoubleLong : public TMatchObject
  2546. {
  2547.     public:
  2548.                                 MPWC TDoubleLong(const TDoubleLong&);
  2549.                                 MPWC TDoubleLong(unsigned long low, long hi);
  2550.                                 MPWC TDoubleLong(long l);
  2551.                                 MPWC TDoubleLong();
  2552.         virtual                    ~ MPWC TDoubleLong();
  2553.     
  2554.         virtual    OSErr            MPWC Inflate(TFormattedStream&);
  2555.         virtual    OSErr            MPWC Flatten(TFormattedStream&) const;
  2556.         
  2557.         virtual Boolean            MPWC IsEqual(const void*) const;
  2558.         virtual unsigned long    MPWC Hash() const;
  2559.         
  2560.         virtual double            MPWC ConvertToDouble() const;
  2561.                                 operator double() const;
  2562.                                 operator unsigned long() const;
  2563.                                 
  2564.         virtual    TDoubleLong&    MPWC Add(const TDoubleLong&);
  2565.         virtual    TDoubleLong&    MPWC Subtract(const TDoubleLong&);
  2566.         virtual    TDoubleLong&    MPWC Multiply(const TDoubleLong&);
  2567.         virtual    TDoubleLong&    MPWC Divide(const TDoubleLong&);
  2568.         virtual    TDoubleLong&    MPWC Modulo(const TDoubleLong&);
  2569.         virtual    TDoubleLong        MPWC RShift(unsigned int) const;
  2570.         virtual    TDoubleLong        MPWC LShift(unsigned int) const;
  2571.         virtual TDoubleLong&    MPWC Negate();
  2572.         virtual short            MPWC Compare(const void*) const;
  2573.         
  2574.                 TDoubleLong&    operator=(const TDoubleLong&);
  2575.                 TDoubleLong&    operator+=(const TDoubleLong&);
  2576.                 TDoubleLong&    operator-=(const TDoubleLong&);
  2577.                 TDoubleLong&    operator*=(const TDoubleLong&);
  2578.                 TDoubleLong&    operator/=(const TDoubleLong&);
  2579.                 TDoubleLong&    operator%=(const TDoubleLong&);
  2580.                 TDoubleLong&    operator&=(const TDoubleLong&);
  2581.                 TDoubleLong&    operator|=(const TDoubleLong&);
  2582.                 TDoubleLong&    operator^=(const TDoubleLong&);
  2583.                 
  2584.                 TDoubleLong        operator+(const TDoubleLong&) const;
  2585.                 TDoubleLong        operator-(const TDoubleLong&) const;
  2586.                 TDoubleLong        operator*(const TDoubleLong&) const;
  2587.                 TDoubleLong        operator/(const TDoubleLong&) const;
  2588.                 TDoubleLong        operator%(const TDoubleLong&) const;
  2589.                 TDoubleLong        operator&(const TDoubleLong&) const;
  2590.                 TDoubleLong        operator|(const TDoubleLong&) const;
  2591.                 TDoubleLong        operator^(const TDoubleLong&) const;
  2592.                 TDoubleLong        operator~() const;
  2593.                 TDoubleLong        operator-() const;
  2594.             
  2595.                 TDoubleLong        operator<<(unsigned int) const;
  2596.                 TDoubleLong        operator>>(unsigned int) const;
  2597.     
  2598.                 Boolean            operator>(const TDoubleLong&) const;
  2599.                 Boolean            operator<(const TDoubleLong&) const;
  2600.                 Boolean            operator<=(const TDoubleLong&) const;
  2601.                 Boolean            operator>=(const TDoubleLong&) const;
  2602.                 Boolean            operator==(const TDoubleLong&) const;
  2603.                 Boolean            operator!=(const TDoubleLong&) const;
  2604.                                 
  2605.     protected:
  2606.         long            fHiBits;
  2607.         unsigned long    fLoBits;
  2608. };
  2609.  
  2610. /*    -----------------------------------------------------------------
  2611.     Inline Methods for TDoubleLong
  2612.     ----------------------------------------------------------------- */
  2613.     
  2614.     inline TDoubleLong::operator unsigned long() const
  2615.     {
  2616.         return fLoBits;
  2617.     }
  2618.     
  2619.     inline TDoubleLong::operator double() const
  2620.     {
  2621.         return ConvertToDouble();
  2622.     }
  2623.     
  2624.     inline TDoubleLong TDoubleLong::operator &(const TDoubleLong& val) const
  2625.     {
  2626.         return TDoubleLong(fLoBits & val.fLoBits, fHiBits & val.fHiBits);
  2627.     }
  2628.     
  2629.     inline TDoubleLong& TDoubleLong::operator =(const TDoubleLong& val)
  2630.     {
  2631.         fHiBits = val.fHiBits;
  2632.         fLoBits = val.fLoBits;
  2633.         return *this;
  2634.     }
  2635.     
  2636.     inline TDoubleLong& TDoubleLong::operator +=(const TDoubleLong& val)
  2637.     {
  2638.         return Add(val);
  2639.     }
  2640.     
  2641.     inline TDoubleLong& TDoubleLong::operator -=(const TDoubleLong& val)
  2642.     {
  2643.         return Subtract(val);
  2644.     }
  2645.     
  2646.     inline TDoubleLong& TDoubleLong::operator *=(const TDoubleLong& val)
  2647.     {
  2648.         return Multiply(val);
  2649.     }
  2650.     
  2651.     inline TDoubleLong& TDoubleLong::operator /=(const TDoubleLong& val)
  2652.     {
  2653.         return Divide(val);
  2654.     }
  2655.             
  2656.     inline TDoubleLong& TDoubleLong::operator %=(const TDoubleLong& val)
  2657.     {
  2658.         return Modulo(val);
  2659.     }
  2660.  
  2661.     inline TDoubleLong& TDoubleLong::operator &=(const TDoubleLong& val)
  2662.     {
  2663.         fHiBits &= val.fHiBits;
  2664.         fLoBits &= val.fLoBits;
  2665.         return *this;
  2666.     }
  2667.     
  2668.     inline TDoubleLong& TDoubleLong::operator |=(const TDoubleLong& val)
  2669.     {
  2670.         fHiBits |= val.fHiBits;
  2671.         fLoBits |= val.fLoBits;
  2672.         return *this;
  2673.     }
  2674.     
  2675.     inline TDoubleLong& TDoubleLong::operator ^=(const TDoubleLong& val)
  2676.     {
  2677.         fHiBits ^= val.fHiBits;
  2678.         fLoBits ^= val.fLoBits;
  2679.         return *this;
  2680.     }
  2681.     
  2682.     inline TDoubleLong TDoubleLong::operator +(const TDoubleLong& val) const
  2683.     {
  2684.         TDoubleLong    temp(*this);
  2685.         (&temp)->Add(val);
  2686.         return temp;
  2687.     }
  2688.     
  2689.     inline TDoubleLong TDoubleLong::operator -(const TDoubleLong& val) const
  2690.     {
  2691.         TDoubleLong    temp(*this);
  2692.         (&temp)->Subtract(val);
  2693.         return temp;
  2694.     }
  2695.     
  2696.     inline TDoubleLong TDoubleLong::operator *(const TDoubleLong& val) const
  2697.     {
  2698.         TDoubleLong    temp(*this);
  2699.         (&temp)->Multiply(val);
  2700.         return temp;
  2701.     }
  2702.     
  2703.     inline TDoubleLong TDoubleLong::operator /(const TDoubleLong& val) const
  2704.     {
  2705.         TDoubleLong    temp(*this);
  2706.         (&temp)->Divide(val);
  2707.         return temp;
  2708.     }
  2709.     
  2710.     inline TDoubleLong TDoubleLong::operator %(const TDoubleLong& val) const
  2711.     {
  2712.         TDoubleLong    temp(*this);
  2713.         (&temp)->Modulo(val);
  2714.         return temp;
  2715.     }
  2716.     
  2717.     inline TDoubleLong TDoubleLong::operator |(const TDoubleLong& val) const
  2718.     {
  2719.         return TDoubleLong(fLoBits | val.fLoBits, fHiBits | val.fHiBits);
  2720.     }
  2721.     
  2722.     inline TDoubleLong TDoubleLong::operator ^(const TDoubleLong& val) const
  2723.     {
  2724.         return TDoubleLong(fLoBits ^ val.fLoBits, fHiBits ^ val.fHiBits);
  2725.     }
  2726.     
  2727.     inline TDoubleLong TDoubleLong::operator~() const
  2728.     {
  2729.         return TDoubleLong(~fLoBits, ~fHiBits);
  2730.     }
  2731.     
  2732.     inline TDoubleLong TDoubleLong::operator -() const
  2733.     {
  2734.         TDoubleLong    temp(*this);
  2735.         (&temp)->Negate();
  2736.         return temp;
  2737.     }
  2738.     
  2739.     inline TDoubleLong TDoubleLong::operator >>(unsigned int val) const
  2740.     {
  2741.         return RShift(val);
  2742.     }
  2743.     
  2744.     inline TDoubleLong TDoubleLong::operator <<(unsigned int val) const
  2745.     {
  2746.         return LShift(val);
  2747.     }
  2748.     
  2749.     inline Boolean TDoubleLong::operator ==(const TDoubleLong& val) const
  2750.     {
  2751.         return fLoBits == val.fLoBits && fHiBits == val.fHiBits;
  2752.     }
  2753.     
  2754.     inline Boolean TDoubleLong::operator !=(const TDoubleLong& val) const
  2755.     {
  2756.         return fLoBits != val.fLoBits || fHiBits != val.fHiBits;
  2757.     }
  2758.  
  2759.     inline Boolean TDoubleLong::operator >(const TDoubleLong& val) const
  2760.     {
  2761.         return Compare(&val) > 0;
  2762.     }
  2763.     
  2764.     inline Boolean TDoubleLong::operator >=(const TDoubleLong& val) const
  2765.     {
  2766.         return Compare(&val) >= 0;
  2767.     }
  2768.     
  2769.     inline Boolean TDoubleLong::operator <(const TDoubleLong& val) const
  2770.     {
  2771.         return Compare(&val) < 0;
  2772.     }
  2773.     
  2774.     inline Boolean TDoubleLong::operator <=(const TDoubleLong& val) const
  2775.     {
  2776.         return Compare(&val) <= 0;
  2777.     }
  2778.     
  2779. /*******************************************************************************
  2780. ** CLASS THashDoubleLong
  2781. **
  2782. ** Class to hash a TDoubleLong.  The 'const void*' parameter is a 
  2783. ** pointer to a TDoubleLong object.
  2784. *******************************************************************************/
  2785.  
  2786. #define kTHashDoubleLongID "slm:supp$hdbl,1.1"
  2787.  
  2788. class THashDoubleLong : public THashObject
  2789. {
  2790.     public:
  2791.                                 MPWC THashDoubleLong();
  2792.         virtual                    ~ MPWC THashDoubleLong();
  2793.         
  2794.         virtual unsigned long    MPWC Hash(const void*) const;
  2795. };
  2796.  
  2797. /*******************************************************************************
  2798. ** CLASS TTime
  2799. **
  2800. ** This is the superclass for all Time-related classes.  Internally,
  2801. ** all times are stored as microSeconds, and the casting operators
  2802. ** for the TTime class return values converted to microseconds.
  2803. *******************************************************************************/
  2804.  
  2805. #define kTTimeID "slm:supp$time,1.1"
  2806.  
  2807. class TTime : public TDoubleLong
  2808. {
  2809.     public:
  2810.                                 MPWC TTime();
  2811.                                 MPWC TTime(unsigned long microseconds);
  2812.                                 MPWC TTime(const TDoubleLong&);
  2813.                                 MPWC TTime(const TTime&);
  2814.         virtual                    ~ MPWC TTime();
  2815.         
  2816.                 void            SetTime(const TTime&);
  2817.                 
  2818.                 void            SetMicroseconds(unsigned long);
  2819.         virtual    void            MPWC SetMilliseconds(unsigned long);
  2820.         virtual    void            MPWC SetSeconds(unsigned long);
  2821.                 
  2822.                 unsigned long    GetMicroseconds() const;
  2823.         virtual    unsigned long    MPWC GetMilliseconds() const;
  2824.         virtual    unsigned long    MPWC GetSeconds() const;
  2825. };
  2826.  
  2827. /*    -----------------------------------------------------------------
  2828.     Inline Methods for TTime
  2829.     ----------------------------------------------------------------- */
  2830.  
  2831.     inline void TTime::SetTime(const TTime& time)
  2832.     {
  2833.         fLoBits    = time.fLoBits;
  2834.         fHiBits    = time.fHiBits;
  2835.     }
  2836.     
  2837.     inline void TTime::SetMicroseconds(unsigned long val)
  2838.     {
  2839.         fLoBits    = val;
  2840.         fHiBits    = 0;
  2841.     }
  2842.     
  2843.     inline unsigned long TTime::GetMicroseconds() const
  2844.     {
  2845.         return fLoBits;
  2846.     }
  2847.  
  2848. /*******************************************************************************
  2849. ** CLASS TMicroseconds
  2850. *******************************************************************************/
  2851.  
  2852. #define kTMicrosecondsID "slm:supp$mics,1.1"
  2853.  
  2854. class TMicroseconds : public TTime
  2855. {
  2856.     public:
  2857.                                 MPWC TMicroseconds();
  2858.                                 MPWC TMicroseconds(unsigned long msecs);
  2859.                                 ~ MPWC TMicroseconds();
  2860.  
  2861.                 operator        unsigned long() const;
  2862.         virtual double            MPWC ConvertToDouble() const;
  2863.                                 operator double() const;
  2864.         
  2865.     private:
  2866.                                 TMicroseconds(const TMicroseconds&);
  2867.                 void            operator=(const TMicroseconds&);
  2868. };
  2869.  
  2870. /*    -----------------------------------------------------------------
  2871.     Inline Methods for TMicroseconds
  2872.     ----------------------------------------------------------------- */
  2873.     
  2874.     inline TMicroseconds::operator unsigned long() const
  2875.     {
  2876.         return GetMicroseconds();
  2877.     }
  2878.  
  2879.     inline TMicroseconds::operator double() const
  2880.     {
  2881.         return ConvertToDouble();
  2882.     }
  2883.  
  2884. /*******************************************************************************
  2885. ** CLASS TMilliseconds
  2886. *******************************************************************************/
  2887.  
  2888. #define kTMillisecondsID "slm:supp$mils,1.1"
  2889.  
  2890. class TMilliseconds : public TTime
  2891. {
  2892.     public:
  2893.                                 MPWC TMilliseconds();
  2894.                                 MPWC TMilliseconds(unsigned long msecs);
  2895.                                 ~ MPWC TMilliseconds();
  2896.  
  2897.                 operator        unsigned long() const;
  2898.         virtual double            MPWC ConvertToDouble() const;
  2899.                                 operator double() const;
  2900.         
  2901.     private:
  2902.                                 TMilliseconds(const TMilliseconds&);
  2903.                 void            operator=(const TMilliseconds&);
  2904. };
  2905.  
  2906. /*    -----------------------------------------------------------------
  2907.     Inline Methods for TMilliseconds
  2908.     ----------------------------------------------------------------- */
  2909.     
  2910.     inline TMilliseconds::operator unsigned long() const
  2911.     {
  2912.         return GetMilliseconds();
  2913.     }
  2914.     
  2915.     inline TMilliseconds::operator double() const
  2916.     {
  2917.         return ConvertToDouble();
  2918.     }
  2919.     
  2920. /*******************************************************************************
  2921. ** CLASS TSeconds
  2922. *******************************************************************************/
  2923.  
  2924. #define kTSecondsID "slm:supp$secs,1.1"
  2925.  
  2926. class TSeconds : public TTime
  2927. {
  2928.     public:
  2929.                                 MPWC TSeconds();
  2930.                                 MPWC TSeconds(unsigned long secs);
  2931.                                 ~ MPWC TSeconds();
  2932.  
  2933.                 operator        unsigned long() const;
  2934.         virtual double            MPWC ConvertToDouble() const;
  2935.                                 operator double() const;
  2936.         
  2937.     private:
  2938.                                 TSeconds(const TSeconds&);
  2939.                 void            operator=(const TSeconds&);
  2940. };
  2941.  
  2942. /*    -----------------------------------------------------------------
  2943.     Inline Methods for TSeconds
  2944.     ----------------------------------------------------------------- */
  2945.  
  2946.     inline TSeconds::operator unsigned long() const
  2947.     {
  2948.         return GetSeconds();
  2949.     }
  2950.     
  2951.     inline TSeconds::operator double() const
  2952.     {
  2953.         return ConvertToDouble();
  2954.     }
  2955.     
  2956. /*******************************************************************************
  2957. ** CLASS TTimeStamp
  2958. *******************************************************************************/
  2959.  
  2960. #define kTTimeStampID "slm:supp$tstm,1.1"
  2961.  
  2962. class TTimeStamp : public TTime
  2963. {
  2964.     public:
  2965.                             MPWC TTimeStamp();
  2966.         virtual                ~ MPWC TTimeStamp();
  2967.     
  2968.         virtual    void        MPWC SetTimeStamp();
  2969.         
  2970.     private:
  2971.                                 TTimeStamp(const TTimeStamp&);
  2972.                 void            operator=(const TTimeStamp&);
  2973. };
  2974.  
  2975. /*******************************************************************************
  2976. ** CLASS TStopwatch
  2977. *******************************************************************************/
  2978.  
  2979. #define kTStopwatchID "slm:supp$stpw,1.1"
  2980.  
  2981. class TStopwatch : public TTimeStamp
  2982. {
  2983.     public:
  2984.                                 MPWC TStopwatch();
  2985.         virtual                    ~ MPWC TStopwatch();
  2986.     
  2987.         virtual    void            MPWC Reset();
  2988.  
  2989.         virtual    unsigned long    MPWC ElapsedMicroseconds() const;
  2990.         virtual    unsigned long    MPWC ElapsedMilliseconds() const;
  2991.         virtual    unsigned long    MPWC ElapsedSeconds() const;
  2992.         
  2993.     private:
  2994.                                 TStopwatch(const TStopwatch&);
  2995.                 void            operator=(const TStopwatch&);
  2996. };
  2997.     
  2998. /*******************************************************************************
  2999. ** CLASS TTraceLog
  3000. **
  3001. ** An object for doing debug tracing with.
  3002. ********************************************************************************/
  3003.  
  3004. #define kTTraceLogID "slm:dbug$tlog,1.1"
  3005.  
  3006. class TTraceLog : public TDynamic 
  3007. {
  3008.     public:
  3009.                                 MPWC TTraceLog();
  3010.         virtual                    ~ MPWC TTraceLog();
  3011.     
  3012.         virtual void            MPWC Trace(char *formatStr, ...) const;
  3013.         
  3014.     // New methods
  3015.         
  3016.                 Boolean            IsTraceLogOn() const;
  3017.                 void            TraceLogOn();
  3018.                 void            TraceLogOff();
  3019.                 
  3020.         virtual    void            MPWC TraceFormatted(char* outstr) const = 0;
  3021.         virtual    void            MPWC TraceUnformatted(void* argp) const;
  3022.  
  3023.     protected:
  3024.                 void            SetTracePool(TStandardPool*);
  3025.                 TStandardPool*    GetTracePool() const;
  3026.  
  3027.     private:
  3028.                                 TTraceLog(const TTraceLog&);
  3029.                 void            operator=(const TTraceLog&);
  3030.         
  3031.         Boolean                    fTracing;
  3032.         TStandardPool*            fTracePool;
  3033. };
  3034.  
  3035. /*    -----------------------------------------------------------------
  3036.     Inline Methods for TTraceLog
  3037.     ----------------------------------------------------------------- */
  3038.  
  3039.     inline Boolean TTraceLog::IsTraceLogOn() const
  3040.     {
  3041.         return fTracing;
  3042.     }
  3043.     
  3044.     inline void TTraceLog::TraceLogOn()
  3045.     {
  3046.         if (fTracePool != NULL)
  3047.             fTracing = true;
  3048.     }
  3049.     
  3050.     inline void TTraceLog::TraceLogOff()
  3051.     {
  3052.         fTracing = false;
  3053.     }
  3054.     
  3055.     inline void TTraceLog::SetTracePool(TStandardPool* pool)
  3056.     {
  3057.         fTracePool = pool;
  3058.     }
  3059.     
  3060.     inline TStandardPool* TTraceLog::GetTracePool() const
  3061.     {
  3062.         return fTracePool;
  3063.     }
  3064.  
  3065. /*******************************************************************************
  3066. ** Some inlines that rely on other inlines so we just do them here to prevent
  3067. ** circular dependency problems.
  3068. ********************************************************************************/
  3069.  
  3070. /*    -------------------------------------------------------------------------
  3071.     Inline methods for TArray
  3072.     ------------------------------------------------------------------------- */
  3073.  
  3074.     inline TStandardPool* TArray::GetGrowPool() const
  3075.     {
  3076.         return (TStandardPool*)TMemoryPool::RecoverPool(fArray);
  3077.     }
  3078.  
  3079. #endif
  3080.  
  3081. #endif
  3082.